Skip to content

Commit dce4dd9

Browse files
ankanenunosilva800
andcommitted
Updated support scripts for LightGBM 4 - #8 [skip ci]
Co-authored-by: Nuno Silva <[email protected]>
1 parent 1596a9e commit dce4dd9

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

test/support/classifier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
print()
3535
print('test_early_stopping')
36-
model.fit(X_train, ym_train, eval_set=[(X_test, ym_test)], early_stopping_rounds=5, verbose=True)
36+
model.fit(X_train, ym_train, eval_set=[(X_test, ym_test)], callbacks=[lgb.early_stopping(stopping_rounds=5), lgb.log_evaluation()])
3737

3838
print()
3939
print('test_missing_numeric')

test/support/cv.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,42 @@
1616
regression_params = {'objective': 'regression', 'verbosity': -1}
1717
regression_train = lgb.Dataset(X_train, label=y_train)
1818
eval_hist = lgb.cv(regression_params, regression_train, shuffle=False, stratified=False)
19-
print(eval_hist['l2-mean'][0])
20-
print(eval_hist['l2-mean'][-1])
21-
print(eval_hist['l2-stdv'][0])
22-
print(eval_hist['l2-stdv'][-1])
19+
print(eval_hist['valid l2-mean'][0])
20+
print(eval_hist['valid l2-mean'][-1])
21+
print(eval_hist['valid l2-stdv'][0])
22+
print(eval_hist['valid l2-stdv'][-1])
2323

2424
print()
2525
print('test_binary')
2626

2727
binary_params = {'objective': 'binary', 'verbosity': -1}
2828
binary_train = lgb.Dataset(X_train, label=y_train.replace(2, 1))
2929
eval_hist = lgb.cv(binary_params, binary_train, shuffle=False, stratified=False)
30-
print(eval_hist['binary_logloss-mean'][0])
31-
print(eval_hist['binary_logloss-mean'][-1])
32-
print(eval_hist['binary_logloss-stdv'][0])
33-
print(eval_hist['binary_logloss-stdv'][-1])
30+
print(eval_hist['valid binary_logloss-mean'][0])
31+
print(eval_hist['valid binary_logloss-mean'][-1])
32+
print(eval_hist['valid binary_logloss-stdv'][0])
33+
print(eval_hist['valid binary_logloss-stdv'][-1])
3434

3535
print()
3636
print('test_multiclass')
3737

3838
multiclass_params = {'objective': 'multiclass', 'num_class': 3, 'verbosity': -1}
3939
multiclass_train = lgb.Dataset(X_train, label=y_train)
4040
eval_hist = lgb.cv(multiclass_params, multiclass_train, shuffle=False, stratified=False)
41-
print(eval_hist['multi_logloss-mean'][0])
42-
print(eval_hist['multi_logloss-mean'][-1])
43-
print(eval_hist['multi_logloss-stdv'][0])
44-
print(eval_hist['multi_logloss-stdv'][-1])
41+
print(eval_hist['valid multi_logloss-mean'][0])
42+
print(eval_hist['valid multi_logloss-mean'][-1])
43+
print(eval_hist['valid multi_logloss-stdv'][0])
44+
print(eval_hist['valid multi_logloss-stdv'][-1])
4545

4646
print('')
4747
print('test_early_stopping_early')
4848

49-
eval_hist = lgb.cv(regression_params, regression_train, shuffle=False, stratified=False, verbose_eval=True, early_stopping_rounds=5)
50-
print(len(eval_hist['l2-mean']))
49+
eval_hist = lgb.cv(regression_params, regression_train, shuffle=False, stratified=False, callbacks=[lgb.log_evaluation(), lgb.early_stopping(stopping_rounds=5)])
50+
print(len(eval_hist['valid l2-mean']))
5151

5252
print('')
5353
print('test_early_stopping_not_early')
5454

55-
eval_hist = lgb.cv(regression_params, regression_train, shuffle=False, stratified=False, verbose_eval=True, early_stopping_rounds=500)
56-
print(len(eval_hist['l2-mean']))
55+
eval_hist = lgb.cv(regression_params, regression_train, shuffle=False, stratified=False, callbacks=[lgb.log_evaluation(), lgb.early_stopping(stopping_rounds=500)])
56+
print(len(eval_hist['valid l2-mean']))
5757

test/support/regressor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
print('feature_importances', model.feature_importances_.tolist())
2020

2121
print('early_stopping')
22-
model.fit(X_train, y_train, eval_set=[(X_test, y_test)], early_stopping_rounds=5, verbose=True)
22+
model.fit(X_train, y_train, eval_set=[(X_test, y_test)], callbacks=[lgb.early_stopping(stopping_rounds=5), lgb.log_evaluation()])

test/support/train.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
regression_params = {'objective': 'regression', 'verbosity': -1}
1818
regression_train = lgb.Dataset(X_train, label=y_train)
1919
regression_test = lgb.Dataset(X_test, label=y_test)
20-
bst = lgb.train(regression_params, regression_train, valid_sets=[regression_train, regression_test], verbose_eval=False)
20+
bst = lgb.train(regression_params, regression_train, valid_sets=[regression_train, regression_test])
2121
y_pred = bst.predict(X_test)
2222
print(np.sqrt(np.mean((y_pred - y_test)**2)))
2323

@@ -27,7 +27,7 @@
2727
binary_params = {'objective': 'binary', 'verbosity': -1}
2828
binary_train = lgb.Dataset(X_train, label=y_train.replace(2, 1))
2929
binary_test = lgb.Dataset(X_test, label=y_test.replace(2, 1))
30-
bst = lgb.train(binary_params, binary_train, valid_sets=[binary_train, binary_test], verbose_eval=False)
30+
bst = lgb.train(binary_params, binary_train, valid_sets=[binary_train, binary_test])
3131
y_pred = bst.predict(X_test)
3232
print(y_pred[0])
3333

@@ -37,28 +37,28 @@
3737
multiclass_params = {'objective': 'multiclass', 'num_class': 3, 'verbosity': -1}
3838
multiclass_train = lgb.Dataset(X_train, label=y_train)
3939
multiclass_test = lgb.Dataset(X_test, label=y_test)
40-
bst = lgb.train(multiclass_params, multiclass_train, valid_sets=[multiclass_train, multiclass_test], verbose_eval=False)
40+
bst = lgb.train(multiclass_params, multiclass_train, valid_sets=[multiclass_train, multiclass_test])
4141
y_pred = bst.predict(X_test)
4242
print(y_pred[0].tolist())
4343

4444
print('')
4545
print('test_early_stopping_early')
4646

47-
bst = lgb.train(regression_params, regression_train, valid_sets=[regression_train, regression_test], early_stopping_rounds=5)
47+
bst = lgb.train(regression_params, regression_train, valid_sets=[regression_train, regression_test], callbacks=[lgb.early_stopping(stopping_rounds=5), lgb.log_evaluation()])
4848
print(bst.best_iteration)
4949

5050
print('')
5151
print('test_early_stopping_not_early')
5252

53-
bst = lgb.train(regression_params, regression_train, valid_sets=[regression_train, regression_test], early_stopping_rounds=500)
53+
bst = lgb.train(regression_params, regression_train, valid_sets=[regression_train, regression_test], callbacks=[lgb.early_stopping(stopping_rounds=500), lgb.log_evaluation()])
5454
# appears to be using training set for best iteration instead of validation set
5555
print(bst.best_iteration)
5656

5757
print('')
5858
print('test_early_stopping_early_higher_better')
5959

6060
params = {'objective': 'binary', 'metric': 'auc', 'verbosity': -1}
61-
bst = lgb.train(params, binary_train, valid_sets=[binary_train, binary_test], early_stopping_rounds=5, verbose_eval=False)
61+
bst = lgb.train(params, binary_train, valid_sets=[binary_train, binary_test], callbacks=[lgb.early_stopping(stopping_rounds=5)])
6262
print(bst.best_iteration)
6363

6464
print('')

0 commit comments

Comments
 (0)