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)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM