我曾经使用 GridSearchCV(...scoring="accuracy"...) 进行分类模型。现在我将使用 GridSearchCV 作为回归模型并使用自己的错误函数设置评分。
示例代码:
def rmse(predict, actual):
predict = np.array(predict)
actual = np.array(actual)
distance = predict - actual
square_distance = distance ** 2
mean_square_distance = square_distance.mean()
score = np.sqrt(mean_square_distance)
return score
rmse_score = make_scorer(rmse)
gsSVR = GridSearchCV(...scoring=rmse_score...)
gsSVR.fit(X_train,Y_train)
SVR_best = gsSVR.best_estimator_
print(gsSVR.best_score_)
但是,我发现它在错误分数最高时返回参数集。结果,我得到了最差的参数集和分数。在这种情况下,我怎样才能得到最好的估计和分数?
概括:
分类 -> GridSearchCV(scoring="accuracy") -> best_estimaror...best
回归 -> GridSearchCV(scroing=rmse_score) -> best_estimator...worst