Created
July 17, 2018 23:58
-
-
Save WillKoehrsen/960d01f133bd7eca2649e8fd727bbd74 to your computer and use it in GitHub Desktop.
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 lightgbm as lgb | |
def objective(hyperparameters, iteration): | |
"""Objective function for grid and random search. Returns | |
the cross validation score from a set of hyperparameters.""" | |
# Number of estimators will be found using early stopping | |
if 'n_estimators' in hyperparameters.keys(): | |
del hyperparameters['n_estimators'] | |
# Perform n_folds cross validation | |
cv_results = lgb.cv(hyperparameters, train_set, num_boost_round = 10000, nfold = N_FOLDS, | |
early_stopping_rounds = 100, metrics = 'auc', seed = 42) | |
# results to retun | |
score = cv_results['auc-mean'][-1] | |
estimators = len(cv_results['auc-mean']) | |
hyperparameters['n_estimators'] = estimators | |
return [score, hyperparameters, iteration] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment