All Products
Search
Document Center

PolarDB:LightGBM algorithm

Last Updated:Sep 23, 2026

This topic describes the LightGBM algorithm.

Introduction

LightGBM (light gradient boosting machine) is a distributed gradient boosting framework based on decision tree algorithms. It is designed to be fast and efficient, featuring low memory usage, high accuracy, and support for parallel and large-scale data processing. LightGBM reduces memory usage, lowers communication costs, and improves efficiency in multi-machine parallel environments. It achieves linear acceleration in data computation.

Scenarios

LightGBM is an algorithm framework that includes models such as GBDT models, random forests, and logistic regression models. It is typically used in scenarios such as binary classification, multiclass classification, and sorting.

For example, in personalized product recommendation scenarios, you often need to create click prediction models. For model creation, you can use past user behaviors, such as clicks, impressions without clicks, and purchases, to predict the probability that a user will click or purchase an item. Features are extracted from user behaviors and properties, including the following:

  • Categorical features: String type, such as gender (male/female).

  • Item types: Clothing, toys, electronics, and more.

  • Numerical features: Integer or floating-point type, such as user popularity or item price.

Parameter descriptions

The following table describes the values for the model_parameter parameter in the CREATE MODEL syntax. You can select the parameters as needed.

Parameter

Description

boosting_type

The type of weak learner. Valid values:

  • gbdt (default): Uses a tree-based model for computation.

  • gblinear: Uses a linear model for computation.

  • rf: Uses a random forest model for computation.

  • dart: Uses the dropout technique to remove some trees and prevent overfitting.

  • goss: Uses the Gradient-based One-Side Sampling (GOSS) algorithm for computation. This method is fast but may lead to underfitting.

Note

Enclose the parameter value in single quotation marks. For example: boosting_type='gbdt'

n_estimators

The number of iterations. This must be an integer. The default value is 100.

loss

The learning task and the corresponding learning objective. Valid values:

  • binary (default): Binary classification.

  • regression: Uses an L2 regularized regression model.

  • regression_l1: Uses an L1 regularized regression model.

  • multiclass: Multiclass classification.

num_leaves

The number of leaves. This must be an integer. The default value is 128.

max_depth

The maximum depth of the tree. This must be an integer. The default value is 7.

Note

A value of -1 indicates an unlimited tree depth. However, to prevent overfitting, it is recommended to set an appropriate value.

learning_rate

The learning rate. This must be a floating-point number. The default value is 0.06.

max_leaf_nodes

The maximum number of leaf nodes in a tree. The value can be empty or an integer. The default value is empty, which means there is no limit on the number of leaf nodes.

min_samples_leaf

The minimum number of samples in a leaf node. This must be an integer. The default value is 20.

Note

If the number of samples in a leaf node is less than this value, it is pruned along with its sibling node.

subsample

The ratio of samples used for model creation to the total number of samples. This must be a floating-point number from 0 to 1. The default value is 1.

Note

If the value is less than 1, only this proportion of the samples is used for model creation.

max_features

The proportion of features to use for model creation. The value is a floating-point number. The valid range is 0 to 1. The default value is 1.

max_depth

The maximum depth of the tree. The value must be an integer. The default value is 7.

Note

A larger value improves accuracy but can cause overfitting.

random_state

The random number seed. This must be an integer. The default value is 1.

Note

Setting different values affects tree construction and the splitting of model creation data.

model_type

The storage class of the model. Valid values:

  • pkl (default): A PKL file.

  • pmml: A Predictive Model Markup Language (PMML) file. This format can display information such as the tree structure.

n_jobs

The number of threads for model creation. This must be an integer. The default value is 4.

Note

A higher number of threads results in faster model creation.

is_unbalance

Specifies whether to increase the weight of classes with fewer samples to address the sample imbalance problem. Valid values:

  • False (default): Does not increase the weight of classes with fewer samples.

  • True: Increases the weight of classes with fewer samples.

categorical_feature

The categorical features. The value is an array of strings. The algorithm typically sets this automatically by checking the data type, but you can also specify it manually.

Example: If the categorical_feature parameter is set to 'AirportTo,DayOfWeek', the `AirportTo` and `DayOfWeek` features are treated as categorical features.

automl

Specifies whether to enable the automatic parameter tuning feature. Valid values:

  • False (default): Disables automatic parameter tuning.

  • True: Enables automatic parameter tuning. When enabled, early stopping is used by default to stop iterations when the learning task and its corresponding objective (the value of the loss parameter) do not improve.

automl_train_tag

The tag for model creation.

automl_test_tag

The tag for testing.

automl_column

The column name used by automatic tuning to distinguish between the model creation set and the development set. When you use this parameter, you must specify automl_column and automl_test_tag. The amount of data for automl_train_tag should be 4 to 9 times larger than the amount of data for automl_test_tag.

Note

Setting the automl_column parameter enables an automatic search for the optimal parameter combination. Add the automl_ prefix to existing parameters, such as learning_rate and subsample, to search for their best values. For example:

automl_column='automl_column',automl_train_tag='train',automl_test_tag='test',automl_learning_rate='0.05,0.04,0.03,0.01',automl_subsample='0.6,0.5'

This configuration searches for the best learning rate from the set {0.05, 0.04, 0.03, 0.01} and the best subsample ratio from the set {0.6, 0.5}.

Examples

Model creation and offline model learning

/*polar4ai*/CREATE MODEL airline_gbm WITH
(model_class = 'lightgbm',
x_cols = 'Airline,Flight,AirportFrom,AirportTo,DayOfWeek,Time,Length',
y_cols='Delay',model_parameter=(boosting_type='gbdt'))
AS (SELECT * FROM db4ai.airlines);

Model evaluation

/*polar4ai*/SELECT Airline FROM EVALUATE(MODEL airline_gbm, 
SELECT * FROM db4ai.airlines LIMIT 20) WITH 
(x_cols = 'Airline,Flight,AirportFrom,AirportTo,DayOfWeek,Time,Length',y_cols='Delay',metrics='acc');

Model prediction

/*polar4ai*/SELECT Airline FROM PREDICT(MODEL airline_gbm,
SELECT * FROM db4ai.airlines limit 20) WITH
(x_cols = 'Airline,Flight,AirportFrom,AirportTo,DayOfWeek,Time,Length');