2

我正在使用 iris 数据集使用 LightGBM 执行多类分类。代码片段如下:

from sklearn import datasets
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
from time import time
from sklearn.metrics import r2_score, mean_squared_error
import lightgbm as lgb
iris = datasets.load_iris()
df_features = iris.data
df_dependent = iris.target
x_train,x_test,y_train,y_test = train_test_split(df_features,df_dependent,test_size=0.3, random_state=2)
params = {
    'task' : 'train',
    'boosting_type' : 'gbdt',
    'objective' : 'multiclass',
    'metric' : {'multi_logloss'},
    'num_leaves' : 63,
    'learning_rate' : 0.1,
    'feature_fraction' : 0.9,
    'bagging_fraction' : 0.9,
    'bagging_freq': 0,
    'verbose' : 0,
    'num_class' : 3
}
lgb_train = lgb.Dataset(x_train, y_train)
lgb_eval = lgb.Dataset(x_test, y_test, reference=lgb_train)
gbm = lgb.train(params,
                lgb_train,
                num_boost_round=20,
                valid_sets=lgb_eval,
                early_stopping_rounds=5)

print('Save model...')
# save model to file
gbm.save_model('model.txt')

在 model.txt 中,我希望 number_of_trees 等于 num_boost_round。但我看到 60 棵树是 num_boost_round*num_class 这是错误的。

为什么会这样?

4

1 回答 1

1

您可以在lightGBM 文档中看到此注释:

注意:在内部,LightGBM 为多类分类问题构建了 num_class * num_iterations 树

于 2019-02-27T13:10:05.617 回答