【问题标题】:How to get average precision, recall, f1, accuracy of cross-validation with sklearn?如何使用sklearn获得交叉验证的平均精度、召回率、f1、准确率?
【发布时间】:2017-03-14 04:44:01
【问题描述】:

我在使用 Weka 对整个训练集进行超参数调整时使用 k 折交叉验证,它显示了交叉验证的平均精度、召回率和 f1。我想在 python 中使用 Sklearn 获得相同的结果。

    cv = StratifiedShuffleSplit(n_splits=5, test_size=0.2, random_state=42)
    grid = GridSearchCV(LinearSVC(), param_grid=param_grid, cv=cv)
    grid.fit(X_train, y_train)
    # print the best parameters
    print("The best parameters are %s with a score of %0.5f"
      % (grid.best_params_, grid.best_score_))
    # print the average precision, recall, f1, accuracy of cross 
    # validation with the best parameters found
    ???

有人可以帮忙吗?

【问题讨论】:

    标签: python scikit-learn cross-validation


    【解决方案1】:

    您可以使用sklearn.metrics 中的classification_report 函数。

    http://scikit-learn.org/stable/modules/generated/sklearn.metrics.classification_report.html

    【讨论】:

    • 嗨,Simon,该链接仅显示训练和/或测试数据的分类报告,我需要的是使用 k 折交叉验证的开发集的平均性能。
    • 在 train 上改装 best_estimator_,在 test 上进行预测;然后调用预测的分类报告。
    猜你喜欢
    • 1970-01-01
    • 2017-11-18
    • 2019-09-06
    • 2018-07-04
    • 2017-05-28
    • 2017-06-02
    • 2017-06-21
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多