python - 测试数据的 f1 分数

标签 python machine-learning scikit-learn

为了获得交叉验证的最佳 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 分数:

关于python - 测试数据的 f1 分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50899221/

相关文章:

machine-learning - 最大池化后 reshape 张量 ValueError : Shapes are not compatible

python - 如何从与 scikit-learn 中的 predict_proba 一起使用的 cross_val_predict 获取类标签

python - 从 sklearn 导入 svm ImportError : cannot import name lsqr

python - 如何使用固定步骤定义自定义 sklearn 管道?

javascript - RESTful GET 资源应如何接受日期时间参数?

python - sklearn DictVectorizer(sparse=False) 具有不同的默认值,估算一个常数

machine-learning - 在什么情况下可以使用 bagging 来代替 boosting?

python - 在同一应用程序中运行Flask和Discord机器人

python - 如何在python中验证用户输入的格式是否正确

python - 在 CSV 编写器中替换\r\n 为\n