Skip to content

Instantly share code, notes, and snippets.

@colobas
Created March 27, 2018 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colobas/083d70f1453924b6a2980ae558823758 to your computer and use it in GitHub Desktop.
Save colobas/083d70f1453924b6a2980ae558823758 to your computer and use it in GitHub Desktop.
from skopt.space import Real, Integer
from skopt.utils import use_named_args
from skopt import gp_minimize
from xgboost import XGBClassifier
from sklearn.model_selection import cross_val_score
cls = XGBClassifier()
space = [
Integer(4, 12, name='max_depth'),
Real(10**-5, 10**0, 'log-uniform', name='learning_rate'),
Integer(5, 200, name='n_estimators'),
Real(0, 0.5, name='gamma'),
Integer(1, 5, name='min_child_weight'),
Real(0.1, 1, name='subsample'),
Real(0.1, 1, name='colsample_bytree')
]
@use_named_args(space)
def objective(**params):
cls.set_params(**params)
return -np.mean(cross_val_score(cls, X, y, cv=5, n_jobs=4,
scoring="neg_mean_absolute_error"))
res_gp = gp_minimize(objective, space, n_calls=50, random_state=0)
"Best score=%.4f" % res_gp.fun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment