Skip to content

Instantly share code, notes, and snippets.

@tldrafael
Last active October 17, 2019 16:45
Show Gist options
  • Save tldrafael/e32c3e09091db1f1bf21fa26174b7471 to your computer and use it in GitHub Desktop.
Save tldrafael/e32c3e09091db1f1bf21fa26174b7471 to your computer and use it in GitHub Desktop.
# Code snippet to train lightgbm models quickly, using the number of iterations based on CV
import lightgbm as lgb
lgb_dftrain = lgb.Dataset(features_train, target_train)
params = {'boosting_type': 'gbdt',
'objective': 'binary',
'enable_bundle': True,
'max_conflict_rate': 0,
'max_depth': 20,
'min_split_gain': 1,
'lambda_l2': 1,
'lambda_l1': 1,
'subsample': 0.5,
'subsample_freq': 1,
'feature_fration': 0.5,
'metric': ['binary_logloss', 'binary_error'],
'learning_rate': 0.03}
cv_hist = lgb.cv(params,
lgb_dftrain,
verbose_eval=10,
num_boost_round=20000,
nfold=3,
stratified=True,
early_stopping_rounds=50,
show_stdv=False)
best_iter = np.argmin(cv_hist['binary_error-mean'])
gbm_model = lgb.train(params,
lgb_dftrain,
verbose_eval=50000,
num_boost_round=best_iter,
valid_sets=lgb_dftrain)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment