|
17 | 17 | regression_params = {'objective': 'regression', 'verbosity': -1}
|
18 | 18 | regression_train = lgb.Dataset(X_train, label=y_train)
|
19 | 19 | 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]) |
21 | 21 | y_pred = bst.predict(X_test)
|
22 | 22 | print(np.sqrt(np.mean((y_pred - y_test)**2)))
|
23 | 23 |
|
|
27 | 27 | binary_params = {'objective': 'binary', 'verbosity': -1}
|
28 | 28 | binary_train = lgb.Dataset(X_train, label=y_train.replace(2, 1))
|
29 | 29 | 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]) |
31 | 31 | y_pred = bst.predict(X_test)
|
32 | 32 | print(y_pred[0])
|
33 | 33 |
|
|
37 | 37 | multiclass_params = {'objective': 'multiclass', 'num_class': 3, 'verbosity': -1}
|
38 | 38 | multiclass_train = lgb.Dataset(X_train, label=y_train)
|
39 | 39 | 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]) |
41 | 41 | y_pred = bst.predict(X_test)
|
42 | 42 | print(y_pred[0].tolist())
|
43 | 43 |
|
44 | 44 | print('')
|
45 | 45 | print('test_early_stopping_early')
|
46 | 46 |
|
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()]) |
48 | 48 | print(bst.best_iteration)
|
49 | 49 |
|
50 | 50 | print('')
|
51 | 51 | print('test_early_stopping_not_early')
|
52 | 52 |
|
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()]) |
54 | 54 | # appears to be using training set for best iteration instead of validation set
|
55 | 55 | print(bst.best_iteration)
|
56 | 56 |
|
57 | 57 | print('')
|
58 | 58 | print('test_early_stopping_early_higher_better')
|
59 | 59 |
|
60 | 60 | 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)]) |
62 | 62 | print(bst.best_iteration)
|
63 | 63 |
|
64 | 64 | print('')
|
|
0 commit comments