Confusion matrix

Here,

• Class 1 : Positive

• Class 2 : Negative

Definition of the Terms:

• Positive (P) : Observation is positive (for example: is an apple).

• Negative (N) : Observation is not positive (for example: is not an apple).

• True Positive (TP) : Observation is positive, and is predicted to be positive.

• False Negative (FN) : Observation is positive, but is predicted negative.

• True Negative (TN) : Observation is negative, and is predicted to be negative.

• False Positive (FP) : Observation is negative, but is predicted positive.

Classification Rate/Accuracy:

Classification Rate or Accuracy is given by the relation:

However, there are problems with accuracy. It assumes equal costs for both kinds of errors. A 99% accuracy can be excellent, good, mediocre, poor or terrible depending upon the problem.

Recall:

Recall can be defined as the ratio of the total number of correctly classified positive examples divide to the total number of positive examples. High Recall indicates the class is correctly recognized (small number of FN).

Recall is given by the relation:

Precision:

To get the value of precision we divide the total number of correctly classified positive examples by the total number of predicted positive examples. High Precision indicates an example labeled as positive is indeed positive (small number of FP).

Precision is given by the relation:

High recall, low precision:This means that most of the positive examples are correctly recognized (low FN) but there are a lot of false positives.

Low recall, high precision:This shows that we miss a lot of positive examples (high FN) but those we predict as positive are indeed positive (low FP)

F-measure:

Since we have two measures (Precision and Recall) it helps to have a measurement that represents both of them. We calculate an F-measure which uses Harmonic Mean in place of Arithmetic Mean as it punishes the extreme values more.

The F-Measure will always be nearer to the smaller value of Precision or Recall.

Below is the Python implementation of above explanation :

# Python script for confusion matrix creation.

from sklearn.metrics import confusion_matrix

from sklearn.metrics import accuracy_score

from sklearn.metrics import classification_report

actual = [1, 1, 0, 1, 0, 0, 1, 0, 0, 0]

predicted = [1, 0, 0, 1, 0, 0, 1, 1, 1, 0]

results = confusion_matrix(actual, predicted)

print 'Confusion Matrix :'

print(results)

print 'Accuracy Score :',accuracy_score(actual, predicted)

print 'Report : '

print classification_report(actual, predicted)

OUTPUT ->

Confusion Matrix :

[[4 2]

[1 3]]

Accuracy Score : 0.7

Report :

precision    recall  f1-score   support

0       0.80      0.67      0.73         6

1       0.60      0.75      0.67         4

avg / total       0.72      0.70      0.70        10

转载:https://www.geeksforgeeks.org/confusion-matrix-machine-learning/

python中confusion matrix_Confusion matrix理解相关推荐

  1. python self 值自动改变,在python中对self的理解

    在python中对self的理解 : 一.self的位置是出现在哪里? 首先,self是在类的方法中的,在调用此方法时,不用给self赋值,Python会自动给他赋值,而且这个值就是类的实例--对象本 ...

  2. Python中if __name__=='__main__': 理解与总结(看这篇就够了,一文扫清疑惑!)

    前言 在Python当中,如果代码写得规范一些,通常会写上一句if '__name__'=='__main__:'作为程序的入口,但似乎没有这么一句代码,程序也能正常运行.这句代码多余吗?原理又在哪里 ...

  3. Python中timedelta类型的理解

    Python中timedelta类型的理解 逻辑: timedelta = datetime1-datetime2 理解:一个时间等于两个时刻做差 代码 import datetimeif __nam ...

  4. python中的引用怎么理解_python 引用和对象理解

    今天浏览博客的时候看到这么一句话: python中变量名和对象是分离的:最开始的时候是看到这句话的时候没有反应过来.决定具体搞清楚一下python中变量与对象之间的细节.(其实我感觉应该说 引用和对象 ...

  5. python中的引用怎么理解_Python函数通过引用调用

    基本上有三种'函数调用':通过价值 通过引用传递 通过对象引用传递 Python是一种PASS-BY-OBJECT-REFERENCE编程语言. 首先,重要的是要理解一个变量,变量(对象)的值是两个独 ...

  6. 对于Python中回调函数的理解

    关于回调函数,网上有很多说明和各种解释,多数在尝试用语言描述.我认为,如果对各个角色之间的关系不清楚,如果没有相关的编程需求,那么语言便非常无力,很难理解. 这是360百科的解释: 在计算机程序设计中 ...

  7. python中的类怎样理解_深入理解Python中的元类(metaclass)

    如何理解python当中的元类 把这个提到外面 class __metaclass__(type): " simple custom metaclass to block adding ne ...

  8. python中self的个人理解

    1. self = 对象自身(self.name =  name,self可以理解为由类创建的实例对象,self.name中的name就是类的属性,而name是外部传来的参数,self.name = ...

  9. Python中的np.array理解

    问题引入 import numpy as np action = [] print(action.append(1)) print(np.array(action)) 结果为: None [1] 为什 ...

  10. python中对GIL的理解

    深入理解Python中的GIL(全局解释器锁) 1. GIL是什么? 首先来看看GIL究竟是什么.我们需要明确的一点是GIL并不是Python的特性,它是在实现Python解析器(CPython)时所 ...

最新文章

  1. Android tabLayout+recyclerView实现锚点定位
  2. 《OpenGL游戏程序设计》学习笔记---第七章图像、位图与OpenGL
  3. python 使用set对list去重,并保持list原来顺序
  4. Transform Model
  5. 【最简代码】1076 Wifi密码 (15分)_8行代码AC
  6. 个人计算机与手机的区别,手机与电脑的CPU是一回事吗?一共有六大区别,看看你知道多少!...
  7. 体验VS2017的Live Unit Testing
  8. wso2 esb_WSO2 ESB的一种消息传递方式
  9. HTML5 Canvas游戏开发实战 PDF扫描版
  10. tda7294参数引脚功能_电容在电路中的几种功能
  11. 自动化wms仓储系统发展五个阶段?
  12. Nginx屏蔽个别User-Agent蜘蛛访问网站的方法
  13. 如何在 Mac 上修改鼠标指针颜色?
  14. 线性回归公式推导与代码实现
  15. 系统动力学Vensim的使用
  16. android无线投屏到电视盒子,如何把电脑视频投屏到智能电视/电视盒子上?
  17. 等级保护三级测评-----云计算安全扩展要求
  18. 黑客用社会工程学做渗透测试的广泛应用介绍
  19. citrix VPX 中申请证书的重点
  20. 搭建Web服务器-迅为IMX6ULL开发板

热门文章

  1. 从JPG和JPEG图片获取压缩比详细教程
  2. 速读水浒!108将的简介与结局
  3. 51单片机按键计数c语言程序,利用AT89C51单片机制作的按键次数计数器
  4. 人生不设限,要勇于去闯_《不如去闯》读书心得
  5. arm-linux 看门狗,S3C6410看门狗源码实例
  6. 京东、搜狗“带狗”都好好的,为何司机对快狗打车不满意?
  7. java栅栏_Java并发工具类(栅栏CyclicBarrier)
  8. k8s命令对node调度 cordon,drain,delete 区别
  9. xp无法搜索计算机,windows xp系统笔记本电脑搜索不到无线信号的解决方法
  10. chromium官方文档