LightGBM icon indicating copy to clipboard operation
LightGBM copied to clipboard

[python package]: training error with categoricals

Open j-mark-hou opened this issue 9 years ago • 3 comments

I just re-built lightgbm from the latest github master on windows with mingw using python setup.py install --mingw (in the same environment where I previously had an older version installed, not sure if it matters).

training with categoricals yields an error. It finishes all the rounds of training, then crashes. Taking out the categoricals makes everything run fine.

import lightgbm as lgb
import numpy as np
import pandas as pd

n=1000
X = np.random.randint(1000, size=(n,2))
y = X[:,0]+X[:,1] + np.random.normal(size=n)

Xtrain, ytrain = X[:int(.5*n),:], y[:int(.5*n)]
Xval, yval = X[int(.5*n):,:], y[int(.5*n):]

ds_train = lgb.Dataset(Xtrain, ytrain)
ds_val = lgb.Dataset(Xval, yval)

params = {'objective':'regression_l2',  'metric':'rmse', 'learning_rate':.1}
gbm = lgb.train(params, ds_train, num_boost_round=200, valid_sets=[ds_val, ds_train], categorical_feature=[1])


---------------------------------------------------------------------------
LightGBMError                             Traceback (most recent call last)
<ipython-input-9-f9fb02a68973> in <module>()
     14 
     15 params = {'objective':'regression_l2',  'metric':'rmse', 'learning_rate':.1}
---> 16 gbm = lgb.train(params, ds_train, num_boost_round=200, valid_sets=[ds_val, ds_train], categorical_feature=[1])
     17 
     18 for i in [1,2,3,4,5,6,7,8,9,10, 50, 100, 150, 200]:

C:\ProgramData\Anaconda3\lib\site-packages\lightgbm\engine.py in train(params, train_set, num_boost_round, valid_sets, valid_names, fobj, feval, init_model, feature_name, categorical_feature, early_stopping_rounds, evals_result, verbose_eval, learning_rates, keep_training_booster, callbacks)
    207         booster.best_score[dataset_name][eval_name] = score
    208     if not keep_training_booster:
--> 209         booster._load_model_from_string(booster._save_model_to_string())
    210         booster.free_dataset()
    211     return booster

C:\ProgramData\Anaconda3\lib\site-packages\lightgbm\basic.py in _load_model_from_string(self, model_str)
   1538             c_str(model_str),
   1539             ctypes.byref(out_num_iterations),
-> 1540             ctypes.byref(self.handle)))
   1541         out_num_class = ctypes.c_int(0)
   1542         _safe_call(_LIB.LGBM_BoosterGetNumClasses(

C:\ProgramData\Anaconda3\lib\site-packages\lightgbm\basic.py in _safe_call(ret)
     45     """
     46     if ret != 0:
---> 47         raise LightGBMError(_LIB.LGBM_GetLastError())
     48 
     49 

LightGBMError: b'stol'

j-mark-hou avatar Aug 03 '17 20:08 j-mark-hou

@wxchan it seem is caused by the save and load model (keep_training_booster=false).

guolinke avatar Aug 04 '17 00:08 guolinke

@j-mark-hou can you try the latest commit ?

guolinke avatar Aug 04 '17 00:08 guolinke

it works. thanks.

j-mark-hou avatar Aug 04 '17 15:08 j-mark-hou