GridSearchCV 自定义评分函数



from
sklearn.metrics import make_scorer
from sklearn.model_selection import GridSearchCV
def my_custom_loss_func(y_true, y_pred): return np.mean(np.abs((y_pred - y_true)/y_true)) mape = make_scorer(my_custom_loss_func, greater_is_better=False)

param_test1 = {
  'n_estimators': [700,800]
}
init_param = { 
  'booster':'gbtree',
  'learning_rate': 0.2,
  'n_estimators': 700,
  'max_depth': 6,
  'min_child_weight': 1,
  'colsample_bytree':0.7,
  'subsample': 0.8,
  'reg_alpha': 0.05,
  'gamma': 0.1,
  'reg_lambda': 3,
  'silent': 1,
  'seed': 2020
}
gsearch1 = GridSearchCV(
  estimator=XGBRFRegressor(**init_param), 
  param_grid=param_test1, cv=5, verbose=1, n_jobs=4, scoring=mape
)
gsearch1.fit(new_train_X, train_y)

 

posted @ 2020-03-10 18:36  orz_cc  阅读(3320)  评论(0)    收藏  举报