将分类报告的准确性返回到列表中

问题描述 投票:0回答:1

我正在使用 Sklean 的分类报告来总结我的训练和测试时期。

sklearn.metrics.classification_report

每个时期我都会得到这样的回报:

>>> from sklearn.metrics import classification_report
>>> y_true
>>> y_pred 
>>> target_names = ['class 0', 'class 1', 'class 2']
>>> print(classification_report(y_true, y_pred, target_names=target_names))
              precision    recall  f1-score   support

     class 0       0.50      1.00      0.67         1
     class 1       0.00      0.00      0.00         1
     class 2       1.00      0.67      0.80         3

    accuracy                           0.60         5
   macro avg       0.50      0.56      0.49         5
weighted avg       0.70      0.60      0.61         5

(例如来自 sklearn 脚本)

现在我正在寻找一种方法,以获得列表中每个时期的准确度,以计算所有准确度的平均值和标准差。

这个问题似乎很微不足道,但正如你在我对 Python/机器学习还很陌生之前从我的问题中看到的那样。

感谢您的帮助

狮子座

python scikit-learn return
1个回答
9
投票

让我们看一下文档,其中包含有关输入参数output_dict的信息:

output_dict : bool (默认 = False) 如果为 True,则以 dict 形式返回输出

如果您拨打

classification_report(y_true, y_pred, target_names=target_names, output_dict=True)
,您可以获得字典。然后你就离你的解决方案只有一个 stackoverflow question 了。

© www.soinside.com 2019 - 2024. All rights reserved.