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

来源:互联网 发布:gis原生数据的采集方法 编辑:程序博客网 时间:2024/06/05 06:14

原文自http://blog.csdn.net/fuhpi/article/details/8813455

  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
  • 2

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

1 0 1 1 0 0 0 0 1 ...
  • 1

  参数outputs也是一个矩阵,代表分类结果,同样每一列表示一个测试样本的分类结果 
  同样如果有两类样本,则应有两个分类器,每一列记录了每个测试样本在两个分类器上的得分,此时outputs为: 
  

0.8 0.85 0.2 0.75 0.21 ...0.8 0.01 0.9 0.23 0.67 ...
  • 1
  • 2

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

0.8 0.6 0.8 0.7 0.05 0.3 0.03 ...
  • 1

注意,得分必须在[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
原创粉丝点击