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:
Note Enclose the parameter value in single quotation marks. For example: |
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:
|
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:
|
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:
|
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 |
automl | Specifies whether to enable the automatic parameter tuning feature. Valid values:
|
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 Note Setting the
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');