要获得交叉验证的最佳f1分数,我会这样做
grid_search = GridSearchCV(pipeline, param_grid=param_grid, cv=10, verbose=10, scoring='f1')
grid_result = grid_search.fit(X_train, y_train)
print("best parameters", grid_search.best_params_)
print('Best score : {}'.format(grid_search.best_score_))
但是对于测试分数,我还需要f1分数而不是准确度
print("Test Score",grid_search.best_estimator_.score(X_test,y_test.reshape(y_test.shape[0])))
是否有任何功能,例如我可以使用的f1_score()
,或者我应该自己编写这个功能吗?
答案 0 :(得分:1)
您可以使用以下方式计算f1分数:
classification report
(example here)
Scikit-learn f1_score函数: (http://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html)