我正在运行GridSearchCV来找到GradientBoostingRegressor的最佳参数。
给出的教程是使用MSE进行评分。
gs_cv = GridSearchCV(est, param_grid, scoring='mean_squared_error', n_jobs=4).fit(X_train, y_train)
是否可以使用其他自己定义的评分,例如均方根对数误差(RMSLE)来获得最佳超参数?
def rmsle(predicted, actual, size):
return np.sqrt(np.nansum(np.square(np.log(predicted + 1) - np.log(actual + 1)))/float(size))
您需要制作一个自定义评分器。在您的情况下,它看起来像这样:
from sklearn.metrics import make_scorer
scorer = make_scorer(rmsle, greater_is_better=False, size=10)
grid = GridSearchCV(est, param_grid, scoring=scorer)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句