confusion matrix

confusion matrix

https://scikit-learn.org/stable/modules/model_evaluation.html

confusion [kən'fjuːʒ(ə)n]:n. 混淆,混乱,困惑

The confusion_matrix function evaluates classification accuracy by computing the confusion matrix with each row corresponding to the true class (Wikipedia and other references may use different convention for axes.)
confusion_matrix 函数通过计算混淆矩阵来评估分类准确性,每个行对应于真实类别 (维基百科和其他引用可以使用不同的轴约定。)

By definition, entry i , j i, j i,j in a confusion matrix is the number of observations actually in group i i i, but predicted to be in group j j j. Here is an example:
根据定义,混淆矩阵中的条目 i , j i, j i,j 是实际在 i i i 组中的观察数,但预计在 j j j 组中。Here is an example:

>>> from sklearn.metrics import confusion_matrix
>>> y_true = [2, 0, 2, 2, 0, 1]
>>> y_pred = [0, 0, 2, 2, 0, 2]
>>> confusion_matrix(y_true, y_pred)
array([[2, 0, 0],
       [0, 0, 1],
       [1, 0, 2]])
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from sklearn.metrics import confusion_matrix

y_true = [2, 0, 2, 2, 0, 1]
y_pred = [0, 0, 2, 2, 0, 2]
print(confusion_matrix(y_true, y_pred))
strong@foreverstrong:~/git_workspace/MonoGRNet$ python yongqiang.py 
[[2 0 0]
 [0 0 1]
 [1 0 2]]
strong@foreverstrong:~/git_workspace/MonoGRNet$

Here is a visual representation of such a confusion matrix (this figure comes from the Confusion matrix example):

在这里插入图片描述

For binary problems, we can get counts of true negatives, false positives, false negatives and true positives as follows:
对于二元问题,我们可以得到真阴性,误报,假阴性和真阳性的计数如下:

>>> y_true = [0, 0, 0, 1, 1, 1, 1, 1]
>>> y_pred = [0, 1, 0, 1, 0, 1, 0, 1]
>>> tn, fp, fn, tp = confusion_matrix(y_true, y_pred).ravel()
>>> tn, fp, fn, tp
(2, 1, 2, 3)

References

https://en.wikipedia.org/wiki/Confusion_matrix

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yongqiang Cheng

梦想不是浮躁,而是沉淀和积累。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值