ROC

本文详细解析了ROC曲线的概念,包括真正率、假正率等关键指标,并阐述了其在评估二分类模型性能时的重要作用。通过解释ROC曲线上关键点的意义,以及如何通过曲线下面积(AUC)来量化模型性能,本文为理解和应用ROC曲线提供了深入的指导。

ROC曲线(Receiver Operating Characteeristic Curve)是显示Classification模型真正率和假正率之间折中的一种图形化方法。

解读ROC图的一些概念定义::

真正(True Positive , TP)被模型预测为正的正样本
假负(False Negative , FN)被模型预测为负的正样本
假正(False Positive , FP)被模型预测为正的负样本
真负(True Negative , TN)被模型预测为负的负样本

真正率(True Positive Rate , TPR)或灵敏度(sensitivity
TPR = TP /(TP + FN)
正样本预测结果数 / 正样本实际数
假负率(False Negative Rate , FNR)
FNR = FN /(TP + FN)
被预测为负的正样本结果数 / 正样本实际数
假正率(False Positive Rate , FPR)
FPR = FP /(FP + TN)
被预测为正的负样本结果数 /负样本实际数
真负率(True Negative Rate , TNR)或特指度(specificity
TNR = TN /(TN + FP)
负样本预测结果数 / 负样本实际数

目标属性的被选中的那个期望值称作是“正”(positive)

ROC曲线上几个关键点的解释:

( TPR=0,FPR=0 ) 把每个实例都预测为负类的模型
( TPR=1,FPR=1 ) 把每个实例都预测为正类的模型
( TPR=1,FPR=0 ) 理想模型


一个好的分类模型应该尽可能靠近图形的左上角,而一个随机猜测模型应位于连接点(TPR=0,FPR=0)和(TPR=1,FPR=1)的主对角线上。

ROC曲线下方的面积(AUC提供了评价模型平均性能的另一种方法。如果模型是完美的,那么它的AUG = 1,如果模型是个简单的随机猜测模型,那么它的AUG = 0.5,如果一个模型好于另一个,则它的曲线下方面积相对较大

下面是一段关于ROC曲线分析应用在二值分类问题的描述:“The ROC analysis applies to binary classification problems. One of the classes is selected as a “positive” one. The ROC chart plots the true positive rate as a function of the false positive rate. It is parametrized by the probability threshold values. The true positive rate represents the fraction of positive cases that were correctly classified by the model. The false positive rate represents the fraction of negative cases that were incorrectly classified as positive. Each point on the ROC plot represents a true_positive_rate/false_positive_rate pair corresponding to a particular probability threshold. Each point has a corresponding confusion matrix. The user can analyze the confusion matrices produced at different threshold levels and select a probability threshold to be used for scoring. The probability threshold choice is usually based on application requirements (i.e., acceptable level of false positives).The ROC does not represent a model. Instead it quantifies its discriminatory ability and assists the user in selecting an appropriate operating point for scoring.”

from :http://www.shoensoft.com/blog/index.php/archives/25

06-17
### ROC 曲线在机器学习中的定义与应用 ROC(Receiver Operating Characteristic)曲线是一种用于评估分类模型性能的工具。它通过绘制假正类率(False Positive Rate, FPR)与真正类率(True Positive Rate, TPR)之间的关系来展示模型的表现[^1]。FPR 是指被错误分类为正类的负样本比例,而 TPR 是指正确分类为正类的正样本比例。 绘制 ROC 曲线时,需要设定不同的阈值以将模型输出的概率转化为类别预测结果。随着阈值的变化,分类器的 TPR 和 FPR 也会随之变化,从而生成一系列点,并最终形成一条曲线[^2]。当阈值的数量越多,ROC 曲线越平滑,能够更准确地反映模型在不同阈值下的表现。 在实际应用中,如果数据集中的正类样本较少,或者对假正类的误判更为敏感,则应优先使用 PR(Precision-Recall)曲线进行评估。否则,ROC 曲线是更常见的选择,尤其是在需要综合考虑模型对正类和负类样本区分能力的情况下[^1]。 此外,AUC(Area Under Curve)是衡量 ROC 曲线下面积的指标,其值介于 0 和 1 之间。较大的 AUC 值表示模型具有更好的分类能力,因为这意味着模型能够更好地对正类和负类样本进行排序[^3]。 ```python from sklearn.metrics import roc_curve, auc import matplotlib.pyplot as plt # 示例代码:绘制 ROC 曲线 y_true = [0, 0, 1, 1] # 真实标签 y_scores = [0.1, 0.4, 0.35, 0.8] # 模型预测的概率 fpr, tpr, thresholds = roc_curve(y_true, y_scores) roc_auc = auc(fpr, tpr) plt.figure() plt.plot(fpr, tpr, color='darkorange', lw=2, label='ROC curve (area = %0.2f)' % roc_auc) plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--') plt.xlim([0.0, 1.0]) plt.ylim([0.0, 1.05]) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate') plt.title('Receiver Operating Characteristic') plt.legend(loc="lower right") plt.show() ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值