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

Vom*_*rfe 3 python return scikit-learn

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

sklearn.metrics.classification_report
Run Code Online (Sandbox Code Playgroud)

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

>>> 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
Run Code Online (Sandbox Code Playgroud)

(例如来自 sklearn 脚本)

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

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

感谢您的帮助

狮子座

Nik*_*ble 9

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

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

如果你打电话就classification_report(y_true, y_pred, target_names=target_names, output_dict=True)可以拿到字典。然后你就离你的解决方案只有一个 stackoverflow问题了。