机器学习之分类器性能指标之ROC曲线、AUC值

转载自:http://blog.csdn.net/zdy0_2004/article/details/44948511


        <h1 class="csdn_top">机器学习之分类器性能指标之ROC曲线、AUC值</h1>
        <div class="article_bar clearfix">
            <div class="artical_tag">
                <span class="original">
                转载                </span>
                <span class="time">2015年04月08日 23:01:21</span>
            </div>

            <ul class="article_tags clearfix csdn-tracking-statistics tracking-click" data-mod="popu_377">
                <li class="tit">标签:</li>

<!--          [startarticletags]-->
                                                            <li><a href="http://so.csdn.net/so/search/s.do?q=机器学习&amp;t=blog" target="_blank">机器学习</a> <span style="display: none;">/</span></li>
                                    <!--          [endarticletags]-->
            </ul>
            <ul class="right_bar">
                <li><button class="btn-noborder"><i class="icon iconfont icon-read"></i><span class="txt">37172</span></button></li>
                <li class="edit" style="display: none;">
                    <a class="btn-noborder" href="http://mp.blog.csdn.net/postedit/44948511">
                        <i class="icon iconfont icon-bianji"></i><span class="txt">编辑</span>
                    </a>
                </li>
                <li class="del" style="display: none;">
                    <a class="btn-noborder" onclick="javascript:deleteArticle(fileName);return false;">
                        <i class="icon iconfont icon-shanchu"></i><span class="txt">删除</span>
                    </a>
                </li>
            </ul>
        </div>
        <div id="article_content" class="article_content csdn-tracking-statistics tracking-click" data-mod="popu_519" data-dsm="post" style="overflow: hidden;">
                            <div class="htmledit_views">
                        
<h1 class="block_title" style="margin:10px 0px 30px; color:rgb(90,90,90); border-bottom-width:0px; border-bottom-style:dashed; border-bottom-color:rgb(204,204,204); padding-left:10px; font-size:14.7px; font-family:verdana,arial; padding-top:0px">
<a target="_blank" id="cb_post_title_url" href="http://www.cnblogs.com/dlml/p/4403482.html" style="color:gray; text-decoration:none">机器学习之分类器性能指标之ROC曲线、AUC值</a></h1>
<div>http://www.cnblogs.com/dlml/p/4403482.html<br>
</div>
<div class="post" style="border:1px dotted rgb(0,0,0); padding:10px; color:rgb(75,75,75); font-family:Verdana,Helvetica,Arial; line-height:18px; text-align:justify">
<div class="postcontent" style="margin-top:10px; color:rgb(48,48,48)">
<div id="cnblogs_post_body" style="margin-bottom:20px; word-break:break-word">
<p style="margin:10px auto" align="center"><strong>分类器性能指标之ROC曲线、AUC值</strong></p>
<p style="margin:10px auto" align="left"><strong>一&nbsp;roc曲线</strong></p>
<p style="margin:10px auto" align="left">1、roc曲线:接收者操作特征(receiveroperating characteristic),roc曲线上每个点反映着对同一信号刺激的感受性。</p>
<p style="margin:10px auto" align="left"><strong>横轴</strong>:负正类率(false postive rate FPR)特异度,划分实例中所有负例占所有负例的比例;(1-Specificity)</p>
<p style="margin:10px auto" align="left"><strong>纵轴</strong>:真正类率(true postive rate TPR)灵敏度,Sensitivity(正类覆盖率)</p>
<p style="margin:10px auto" align="left">2针对一个二分类问题,将实例分成正类(postive)或者负类(negative)。但是实际中分类时,会出现四种情况.</p>
<p style="margin:10px auto" align="left">(1)若一个实例是正类并且被预测为正类,即为真正类(True Postive TP)</p>
<p style="margin:10px auto" align="left">(2)若一个实例是正类,但是被预测成为负类,即为假负类(False Negative FN)</p>
<p style="margin:10px auto" align="left">(3)若一个实例是负类,但是被预测成为正类,即为假正类(False Postive FP)</p>
<p style="margin:10px auto" align="left">(4)若一个实例是负类,但是被预测成为负类,即为真负类(True Negative TN)</p>
<p style="margin:10px auto" align="left"><strong>TP</strong>:正确的肯定数目</p>
<p style="margin:10px auto" align="left"><strong>FN</strong>:漏报,没有找到正确匹配的数目</p>
<p style="margin:10px auto" align="left"><strong>FP</strong>:误报,没有的匹配不正确</p>
<p style="margin:10px auto" align="left"><strong>TN</strong>:正确拒绝的非匹配数目</p>
<p style="margin:10px auto" align="left">列联表如下,1代表正类,0代表负类:</p>
<p style="margin:10px auto" align="left"><img src="http://images.cnitblog.com/blog2015/712297/201504/081953479158732.jpg" alt="" style="border:0px"></p>
<p style="margin:10px auto" align="left">由上表可得出横,纵轴的计算公式:</p>
<p style="margin:10px auto" align="left">(1)真正类率(True Postive Rate)TPR:&nbsp;<strong>TP/(TP+FN)</strong>,代表分类器预测的<strong>正类中</strong>实际正实例占所有正实例的比例。Sensitivity</p>
<p style="margin:10px auto" align="left">(2)负正类率(False Postive Rate)FPR:<strong>&nbsp;FP/(FP+TN)</strong>,代表分类器预测的<strong>正类中</strong>实际负实例占所有负实例的比例。1-Specificity</p>
<p style="margin:10px auto" align="left">(3)真负类率(True Negative Rate)TNR:<strong>&nbsp;TN/(FP+TN)</strong>,代表分类器预测的<strong>负类中</strong>实际负实例占所有负实例的比例,<strong>TNR=1-FPR</strong>。Specificity</p>
<p style="margin:10px auto" align="left">假设采用逻辑回归分类器,其给出针对每个实例为正类的概率,那么通过设定一个阈值如0.6,概率大于等于0.6的为正类,小于0.6的为负类。对应的就可以算出一组(FPR,TPR),在平面中得到对应坐标点。随着阈值的逐渐减小,越来越多的实例被划分为正类,但是这些正类中同样也掺杂着真正的负实例,即TPR和FPR会同时增大。阈值最大时,对应坐标点为(0,0),阈值最小时,对应坐标点(1,1)。</p>
<p style="margin:10px auto" align="left">如下面这幅图,(a)图中实线为ROC曲线,线上每个点对应一个阈值。</p>
<p style="margin:10px auto" align="left">&nbsp;<img src="http://images.cnitblog.com/blog2015/712297/201504/081954327748728.jpg" alt="" style="border:0px"></p>
<p style="margin:10px auto" align="left">横轴FPR:1-TNR,1-Specificity,FPR越大,预测正类中实际负类越多。</p>
<p style="margin:10px auto" align="left">纵轴TPR:Sensitivity(正类覆盖率),TPR越大,预测正类中实际正类越多。</p>
<p style="margin:10px auto" align="left">理想目标:TPR=1,FPR=0,<strong>即图中(0,1)点,故ROC曲线越靠拢(0,1)点,越偏离45度对角线越好,</strong>Sensitivity、Specificity<strong>越大效果越好。</strong></p>
<p style="margin:10px auto" align="left"><strong>二 如何画</strong>roc<strong>曲线</strong></p>
<p style="margin:10px auto" align="left">假设已经得出一系列样本被划分为正类的概率,然后按照大小排序,下图是一个示例,图中共有20个测试样本,“Class”一栏表示每个测试样本真正的标签(p表示正样本,n表示负样本),“Score”表示每个测试样本属于正样本的概率。</p>
<p style="margin:10px auto" align="center"><img src="http://images.cnitblog.com/blog2015/712297/201504/081954549307426.jpg" alt="" style="border:0px">&nbsp;</p>
<p style="margin:10px auto" align="left">接下来,我们从高到低,依次将“Score”值作为阈值threshold,当测试样本属于正样本的概率大于或等于这个threshold时,我们认为它为正样本,否则为负样本。举例来说,对于图中的第4个样本,其“Score”值为0.6,那么样本1,2,3,4都被认为是正样本,因为它们的“Score”值都大于等于0.6,而其他样本则都认为是负样本。每次选取一个不同的threshold,我们就可以得到一组FPR和TPR,即ROC曲线上的一点。这样一来,我们一共得到了20组FPR和TPR的值,将它们画在ROC曲线的结果如下图:</p>
<p style="margin:10px auto" align="left">&nbsp;<img src="http://images.cnitblog.com/blog2015/712297/201504/081955100088586.jpg" alt="" style="border:0px">&nbsp;</p>
<p style="margin:10px auto" align="left">AUC(Area under Curve):Roc曲线下的面积,介于0.1和1之间。Auc作为数值可以直观的评价分类器的好坏,值越大越好。</p>
<p style="margin:10px auto" align="left"><strong>首先AUC值是一个概率值,当你随机挑选一个正样本以及负样本,当前的分类算法根据计算得到的Score值将这个正样本排在负样本前面的概率就是AUC值,AUC值越大,当前分类算法越有可能将正样本排在负样本前面,从而能够更好地分类。</strong></p>
<p style="margin:10px auto" align="left"><strong>三 为什么使用Roc和Auc评价分类器</strong></p>
<p style="margin:10px auto" align="left">既然已经这么多标准,为什么还要使用ROC和AUC呢?因为ROC曲线有个很好的特性:当测试集中的正负样本的分布变换的时候,ROC曲线能够保持不变。在实际的数据集中经常会出现样本类不平衡,即正负样本比例差距较大,而且测试数据中的正负样本也可能随着时间变化。下图是ROC曲线和Presision-Recall曲线的对比:</p>
<p style="margin:10px auto" align="center"><img src="http://images.cnitblog.com/blog2015/712297/201504/081955410556234.jpg" alt="" style="border:0px">&nbsp;</p>
<p style="margin:10px auto" align="left">在上图中,(a)和(c)为Roc曲线,(b)和(d)为Precision-Recall曲线。</p>
<p style="margin:10px auto" align="left">(a)和(b)展示的是分类其在原始测试集(正负样本分布平衡)的结果,(c)(d)是将测试集中负样本的数量增加到原来的10倍后,分类器的结果,可以明显的看出,ROC曲线基本保持原貌,而Precision-Recall曲线变化较大。</p>
<p style="margin:10px auto" align="left">参考:</p>
<p style="margin:10px auto" align="left"><a target="_blank" href="http://alexkong.net/2013/06/introduction-to-auc-and-roc/" style="color:gray; text-decoration:none">http://alexkong.net/2013/06/introduction-to-auc-and-roc/</a></p>
<p style="margin:10px auto" align="left"><a target="_blank" href="http://blog.csdn.net/abcjennifer/article/details/7359370" style="color:gray; text-decoration:none">http://blog.csdn.net/abcjennifer/article/details/7359370</a></p>
</div>
<div class="clear" style="clear:both"></div>
<div id="blog_post_info_block" style="margin-top:20px">
<div id="BlogPostCategory" style="margin-bottom:10px">分类:&nbsp;<a target="_blank" href="http://www.cnblogs.com/dlml/category/676179.html" style="color:gray; text-decoration:none">机器学习</a></div>
</div>
</div>
</div>
                </div>
                    </div>
   

猜你喜欢

转载自blog.csdn.net/cdknight_happy/article/details/79444860
今日推荐