Skip to content

Commit a2af377

Browse files
author
Sergey Feldman
committed
go back to random
1 parent a945310 commit a2af377

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

02_lightgbm.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@
66
import pickle
77
import numpy as np
88
import lightgbm as lgb
9-
from skopt import BayesSearchCV
10-
from skopt.space import Real, Categorical, Integer
9+
from sklearn.model_selection import RandomizedSearchCV
1110
from sklearn.model_selection import cross_val_score, StratifiedKFold
1211
from utils import load_data
1312

14-
N_JOBS = 4 * 4
13+
N_JOBS = 4 * 4 * 9
1514
N_ITER = 25 # budget for hyperparam search
1615

1716

1817
def evaluate_pipeline_helper(X, y, pipeline, param_grid, random_state=0):
1918
inner_cv = StratifiedKFold(n_splits=4, shuffle=True, random_state=random_state)
2019
outer_cv = StratifiedKFold(n_splits=4, shuffle=True, random_state=random_state)
21-
clf = BayesSearchCV(
20+
clf = RandomizedSearchCV(
2221
estimator=pipeline,
23-
search_spaces=param_grid,
22+
param_distributions=param_grid,
2423
n_iter=N_ITER,
25-
n_points=3,
2624
cv=inner_cv,
2725
scoring="roc_auc_ovr_weighted",
2826
n_jobs=N_JOBS,
@@ -37,7 +35,7 @@ def define_and_evaluate_lightgbm_pipeline(X, y, random_state=0):
3735
if len(set(y)) == 2:
3836
pipeline = lgb.LGBMClassifier(
3937
objective="binary",
40-
n_estimators=1000,
38+
n_estimators=500,
4139
metric="auc",
4240
verbose=-1,
4341
tree_learner="feature",
@@ -47,23 +45,23 @@ def define_and_evaluate_lightgbm_pipeline(X, y, random_state=0):
4745
else:
4846
pipeline = lgb.LGBMClassifier(
4947
objective="multiclass",
50-
n_estimators=1000,
48+
n_estimators=500,
5149
metric="auc_mu",
5250
verbose=-1,
5351
tree_learner="feature",
5452
random_state=random_state,
5553
silent=True,
5654
)
5755
param_grid = {
58-
"learning_rate": Real(1e-7, 1e+0, prior='log-uniform'), #[1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0],
59-
"num_leaves": Categorical([1, 3, 15, 31, 63, 127]), # 2**depth - 1
60-
"colsample_bytree": Categorical([0.5, 0.6, 0.7, 0.8, 0.9, 1.0]),
61-
"subsample": Categorical([0.5, 0.6, 0.7, 0.8, 0.9, 1.0]),
62-
"min_child_samples": Categorical([1, 2, 4, 8, 16, 32, 64, 128, 256]),
63-
"min_child_weight": Real(1e-7, 1e+0, prior='log-uniform'), # [1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0],
64-
"reg_alpha": Real(1e-7, 1e+0, prior='log-uniform'), # [1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0],
65-
"reg_lambda": Real(1e-7, 1e+0, prior='log-uniform'), # [1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0],
66-
"max_depth": [1, 2, 4, 8, 16, -1],
56+
"learning_rate": [1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0],
57+
"num_leaves": [2, 4, 8, 16, 32, 64],
58+
"colsample_bytree": [0.5, 0.6, 0.7, 0.8, 0.9, 1.0],
59+
"subsample": [0.5, 0.6, 0.7, 0.8, 0.9, 1.0],
60+
"min_child_samples": [2, 4, 8, 16, 32, 64, 128, 256],
61+
"min_child_weight": [1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0],
62+
"reg_alpha": [1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0],
63+
"reg_lambda": [1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0],
64+
"max_depth": [1, 2, 4, 8, 16, 32, -1],
6765
}
6866
nested_scores = evaluate_pipeline_helper(X, y, pipeline, param_grid, random_state=random_state)
6967
return nested_scores

0 commit comments

Comments
 (0)