我有以下内容:
from sklearn.model_selection import GridSearchCV
from sklearn.ensemble import RandomForestClassifier as RFC
par = {"n_estimators":n_estimators,
"max_depth":max_depth,
"class_weight":weight}
scores = {"AUC":"roc_auc","score":my_score} #Scores metric
rfc=RFC()
grid_rfc=GridSearchCV(rfc,
param_grid=par,
cv=10,
scoring=scores,
iid=False,
refit="AUC")
grid_rfc.fit(x_train,y_train)
然后我可以使用grid_rfc.best_param
获得最佳参数,但是未列出提供最佳参数的score
。
据我了解,score
是RFC
试图最大化的那个,所以我不明白为什么它不在最佳参数中。
编辑:
我缺少的不是RF产生的得分,而是使用了哪个得分函数来拟合给出最佳结果的树(例如,score
字典中的“ AUC”或“ my_score” )
答案 0 :(得分:0)
根据GridSearchCV documentation,您可以使用best_score_
中的best_param_
获得最佳分数。
由于您的代码不完整,我无法测试此示例,但是实现应如下所示:
from sklearn.model_selection import GridSearchCV
from sklearn.ensemble import RandomForestClassifier as RFC
par = {"n_estimators":n_estimators,
"max_depth":max_depth,
"class_weight":weight}
scores = {"AUC":"roc_auc","score":my_score} #Scores metric
rfc=RFC()
grid_rfc=GridSearchCV(rfc,
param_grid=par,
cv=10,
scoring=scores,
iid=False,
refit="AUC")
grid_rfc.fit(x_train,y_train)
# Print the best score
print(grid.best_score_)
现在您可能会注意到它看起来与真实的precision
略有不同,因此请参见this Stack Overflow post进行更多讨论。