R混淆矩阵敏感性和特异性标记 [英] R Confusion Matrix sensitivity and specificity labeling

查看:70
本文介绍了R混淆矩阵敏感性和特异性标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 R v3.3.2 和 Caret 6.0.71(即最新版本)来构建逻辑回归分类器.我正在使用混淆矩阵函数来创建用于判断其性能的统计数据.

I am using R v3.3.2 and Caret 6.0.71 (i.e. latest versions) to construct a logistic regression classifier. I am using the confusionMatrix function to create stats for judging its performance.

logRegConfMat <-混淆矩阵(logRegPrediction, valData[,"Seen"])

logRegConfMat <- confusionMatrix(logRegPrediction, valData[,"Seen"])

  • 参考 0,预测 0 = 30
  • 参考文献 1,预测 0 = 14
  • 参考 0,预测 1 = 60
  • 参考文献 1,预测 1 = 164

准确度:0.7239
灵敏度:0.3333
特异性:0.9213

Accuracy : 0.7239
Sensitivity : 0.3333
Specificity : 0.9213

我的数据 (Seen) 中的目标值使用 1 表示真,0 表示假.我假设混淆矩阵中的参考(基本事实)列和谓词(分类器)行遵循相同的约定.因此我的结果显示:

The target value in my data (Seen) uses 1 for true and 0 for false. I assume the Reference (Ground truth) columns and Predication (Classifier) rows in the confusion matrix follow the same convention. Therefore my results show:

  • 真阴性 (TN) 30
  • 真阳性 (TP) 164
  • 假阴性 (FN) 14
  • 误报 (FP) 60

问题:为什么灵敏度为 0.3333,特异性为 0.9213?我会认为这是相反的 - 见下文.

我不愿意相信 R 混淆矩阵函数中存在错误,因为没有报告任何内容,这似乎是一个重大错误.

I am reluctant to believe that there is bug in the R confusionMatrix function as nothing has been reported and this seems to be a significant error.

大多数关于计算特异性和敏感性的参考文献将它们定义如下 - 即 www.medcalc.org/calc/diagnostic_test.php

Most references about calculating specificity and sensitivity define them as follows - i.e. www.medcalc.org/calc/diagnostic_test.php

  • 灵敏度 = TP/(TP+FN) = 164/(164+14) = 0.9213
  • 特异性 = TN/(FP+TN) = 30/(60+30) = 0.3333

推荐答案

根据文档?confusionMatrix:

"如果只有两个因子水平,则第一个水平将用作阳性"结果."

"If there are only two factor levels, the first level will be used as the "positive" result."

因此,在您的示例中,正面结果将是 0,并且评估指标将是错误的.要覆盖默认行为,您可以将参数 positive = 设置为正确的值,唉:

Hence in your example positive result will be 0, and evaluation metrics will be the wrong way around. To override default behaviour, you can set the argument positive = to the correct value, alas:

 confusionMatrix(logRegPrediction, valData[,"Seen"], positive = "1")

这篇关于R混淆矩阵敏感性和特异性标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆