classification metrics in sklear

2020-05-09  本文已影响0人  汉江岳
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, confusion_matrix, classification_report


y_pred = ["a", "b", "c", "a", "b", 'a', 'c', 'b']
y_act = ["a", "b", "c", "c", "a", 'a', 'c', 'b']
confusion_matrix(y_act, y_pred, labels=['a', 'b', 'c'])
image.png

可以看出,confusion matrix 实际上是对所有测试样本,分类结果的统计,是一个大小为类别个数的方阵,row表示actual label, column表示predicted label。
从行看:

从列看:

关于 precision 、 f1-score的定义这里不赘述,特别说下false-positive-rate、true-positive-rate及sklearn中support、 macro avg、micro avg、weighted avg的含义。

ROC曲线:是以 true-positive-rate 为纵轴,false-positive-rate 为横轴,通过对测试样本(越多越好,越多画出来的roc曲线越平滑),设置不同的分类器分类阈值画出的,设置一个阈值,可以在测试集上计算出一组(false-positive-rate, true-positive-rate),即一个坐标点。
AUC 是分类器ROC曲线的线下面积,取值0.5~1之间。一般采用近似计算得出,调包计算就行,计算原理可以不懂,明白概念就行。

这些概念是针对二分类的,但都可以拓展到多分类。

理解这些分类统计指标的关键:弄清楚其代表的本质是什么,不要被高大上的命名给吓到!!!

参考:

  1. https://www.jianshu.com/p/c61ae11cc5f6
  2. https://blog.csdn.net/YE1215172385/article/details/79443552
  3. https://blog.csdn.net/qq_38410428/article/details/88106395
上一篇 下一篇

猜你喜欢

热点阅读