Skip to content

Instantly share code, notes, and snippets.

@jrzaurin
Last active March 9, 2019 12:40
Show Gist options
  • Save jrzaurin/eac5f91553dcf2272e49648d39c91ba6 to your computer and use it in GitHub Desktop.
Save jrzaurin/eac5f91553dcf2272e49648d39c91ba6 to your computer and use it in GitHub Desktop.
def objective(params):
"""
objective function for lightgbm.
"""
# hyperopt casts as float
params['num_boost_round'] = int(params['num_boost_round'])
params['num_leaves'] = int(params['num_leaves'])
# need to be passed as parameter
params['is_unbalance'] = True
params['verbose'] = -1
params['seed'] = 1
cv_result = lgb.cv(
params,
train,
num_boost_round=params['num_boost_round'],
metrics='binary_logloss',
nfold=3,
stratified=True,
early_stopping_rounds=20)
early_stop_dict[objective.i] = len(cv_result['binary_logloss-mean'])
error = cv_result['binary_logloss-mean'][-1]
objective.i+=1
return error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment