abhishek jha
abhishek jha

Reputation: 1095

Number of trees in multiclass classification in LightGBM

I am using iris dataset to perform multi-class classification using LightGBM. The code snippet is given below:

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')

In the model.txt, I expected the number_of_trees to be equal to num_boost_round. but I see 60 trees which is num_boost_round*num_class which is wrong.

Why is this happening?

Upvotes: 3

Views: 3592

Answers (1)

A simple guy
A simple guy

Reputation: 36

You can see this note in lighGBM documentation:

Note: internally, LightGBM constructs num_class * num_iterations trees for multi-class classification problems

Upvotes: 2

Related Questions