Created
October 3, 2018 13:29
-
-
Save vikramsoni2/cf646034320074f6fc67132fc115ec9f to your computer and use it in GitHub Desktop.
lightgbm classifier bayesian optimization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd; | |
import numpy as np; | |
import lightgbm as lgb | |
from bayes_opt import BayesianOptimization | |
from sklearn.model_selection import cross_val_score | |
def lgb_evaluate( | |
numLeaves, | |
maxDepth, | |
scaleWeight, | |
minChildWeight, | |
subsample, | |
colSam | |
): | |
clf = lgb.LGBMClassifier( | |
objective = 'binary', | |
metric= 'auc', | |
eval_metric= 'auc', | |
reg_alpha= 0, | |
reg_lambda= 2, | |
bagging_fraction= 0.999, | |
min_split_gain= 0, | |
min_child_samples= 10, | |
subsample_freq= 3, | |
subsample_for_bin= 50000, | |
n_estimators= 9999999, | |
num_leaves= int(numLeaves), | |
max_depth= int(maxDepth), | |
scale_pos_weight= scaleWeight, | |
min_child_weight= minChildWeight, | |
subsample= subsample, | |
colsample_bytree= colSam, | |
verbose =-1 | |
) | |
scores = cross_val_score(clf, train_x, train_y, cv=5, scoring='roc_auc') | |
print(np.mean(scores)) | |
return np.mean(scores) | |
def bayesOpt(train_x, train_y): | |
lgbBO = BayesianOptimization(lgb_evaluate, { | |
'numLeaves': (5, 50), | |
'maxDepth': (2, 63), | |
'scaleWeight': (1, 10000), | |
'minChildWeight': (0.01, 70), | |
'subsample': (0.4, 1), | |
'colSam': (0.4, 1) | |
}) | |
lgbBO.maximize(init_points=5, n_iter=5) | |
print(lgbBO.res['max']) | |
bayesOpt(train_x, train_y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment