使用Maltlab中的plotroc()函数绘制ROC曲线

ROC曲线是通用的分类器评价工具,matlab函数中自带了绘制该曲线的函数plotroc。

plotroc函数的原型为:plotroc(targets, outputs)

其中参数targets是一个矩阵,代表测试集,每一列表示一个测试样本的标签

如果有两类样本,比如第1,2,5个样本属于第1类,第3,4,6个样本属于第2类....则targets应为:

1 1 0 0 1 0 ...

0 0 1 1 0 1 ...

如果只有一类样本,包含了负样本,则只要一行,用1表示正样本,0表示负样本即可,比如targets为:

1 0 1 1 0 0 0 0 1 ...


参数outputs也是一个矩阵,代表分类结果,同样每一列表示一个测试样本的分类结果

同样如果有两类样本,则应有两个分类器,每一列记录了每个测试样本在两个分类器上的得分,此时outputs为:

0.8 0.85 0.2 0.75 0.21 ...

0.8 0.01 0.9 0.23 0.67 ...

如果只有一类,则outputs只有一行,如:

0.8 0.6 0.8 0.7 0.05 0.3 0.03 ...

注意,得分必须在[0, 1]的区间内,可以自己规约一下。

我们将相应的测试标签targets和对应的分类得分outputs输入plotroc中就可以绘制出相应的ROC曲线了。

有人问起,我也就在网上搜了一下,发现还有很多人不会用,写下来以供参考,欢迎指正。


补记:似乎使用matlab中的plot()与roc()组合也能完成ROC曲线绘制。


matlab中还给出了一个例子,帮助信息如下:

>> help plotroc
 plotroc Plot receiver operating characteristic.
 
  plotroc(targets,outputs) takes target data in 1-of-N form (each column
  vector is all zeros with a single 1 indicating the class number), and
  output data and generates a receiver operating characteristic plot.
 
  The best classifications will show the receiver operating line hugging
  the left and top sides of the plots axis.
 
  plotroc(targets,1,outputs1,'name1',targets2,outputs2,names2,...)
  generates a variable number of confusion plots in one figure.
 
  Here a pattern recognition network is trained and its accuracy plotted:
 
    [x,t] = simpleclass_dataset;
    net = patternnet(10);
    net = train(net,x,t);
    y = net(x);
    plotroc(t,y);
 
  See also roc, plotconfusion, ploterrhist, plotregression.


    Reference page in Help browser
       doc plotroc



  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值