为了获得交叉验证的最佳 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-score 而不是准确性
print("Test Score",grid_search.best_estimator_.score(X_test,y_test.reshape(y_test.shape[0])))
是否有我可以使用的函数,例如 f1_score()
或者我应该自己编写该函数?
最佳答案
您可以通过以下方式计算 f1 分数:
分类报告
(example here)Scikit-learn f1_score 函数: (http://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html)
关于python - 测试数据的 f1 分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50899221/