microsoft / LightGBM

A fast, distributed, high performance gradient boosting (GBT, GBDT, GBRT, GBM or MART) framework based on decision tree algorithms, used for ranking, classification and many other machine learning tasks.
https://lightgbm.readthedocs.io/en/latest/
MIT License
16.56k stars 3.82k forks source link

Got python automatic termination error when runing multiclass #732

Closed deepx-top closed 7 years ago

deepx-top commented 7 years ago

Please search your question on previous issues, stackoverflow or other search engines before you open a new one.

For bugs and unexpected issues, please provide following information, so that we could reproduce on our system.

Environment info

Operating System:windows 10 CPU: E5200 C++/Python/R version: Python 3.5.2

Error Message:

Just python termination when training

Reproducible examples

I‘m using LightGBM in Kaggle Mnist competition(https://www.kaggle.com/c/digit-recognizer), and got 97.37%。when i run the code again,I got python termination error every time,but when i change parameter "multiclass” to "regress" and removing “num_class”, the code working fine. So is it a "multiclass” bug or i just need to update my environment ?

Steps to reproduce

1.The main code:

import numpy as np
import pandas as pd
import lightgbm as lgb
from sklearn.model_selection import train_test_split

trains = pd.read_csv("./train.csv")
tests = pd.read_csv("./test.csv")
train, valid = train_test_split(trains, test_size=0.25, random_state=1)
train_x = np.asarray(train.iloc[:, 1:].values).astype(np.float32)
train_y = np.asarray(train.iloc[:, 0].values)
valid_x = np.asarray(valid.iloc[:, 1:].values).astype(np.float32)
valid_y = np.asarray(valid.iloc[:, 0].values)
test_x = np.asarray(tests.values).astype(np.float32)
lgb_train = lgb.Dataset(train_x, label=train_y)
lgb_valid = lgb.Dataset(valid_x, label=valid_y)
lgb_test = lgb.Dataset(test_x)

params = {
    'task': 'train',
    'boosting_type': 'gbdt',
    'objective': 'multiclass',
    'num_class': 10,
    'metric': {'l2', 'auc'},
    'num_leaves': 31,
    'learning_rate': 0.05,
    'feature_fraction': 0.9,
    'bagging_fraction': 0.8,
    'bagging_freq': 5,
    'verbose': 1
}
print('Start training...')
gbm = lgb.train(params,
                lgb_train,
                num_boost_round=20,
                valid_sets=lgb_valid,
                early_stopping_rounds=200,
                verbose_eval=10
                )
print('Save model...')
gbm.save_model('model.txt')
guolinke commented 7 years ago

@deepx-top for the multi-class, you cannot use "l2" and "auc" metric. please try the multi_logloss or multi_error . BTW, early_stopping_rounds cannot exceed the num_boost_round.

deepx-top commented 7 years ago

It works, thanks @guolinke

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.