在Matlab中绘制ROC曲线

时间:2016-08-19 14:26:35

标签: matlab roc

我需要在matlab中绘制一条ROC曲线。我有两个数组,一个包含真正的阳性率,另一个包含误报率。我已经尝试将两个数组作为输入plotrocperfcurve,但它似乎不起作用。还有另一种方法可以用我拥有的数据绘制ROC曲线吗?

修改 我发布的图片是为了回答Tasos Papastylianou:

enter image description here

简单地绘制两个数组,它看起来并不像ROC曲线:S

EDIT2 上传倒映射的图像,仍然看起来不像ROC! enter image description here

EDIT3 显示我的ROC曲线图的图像,标准化为[0,1] [enter image description here] 3

2 个答案:

答案 0 :(得分:1)

我想我会用一个漂亮的ROC曲线示例发布一个正确的答案,展示我们在评论中讨论的内容:

%% Create datasets

[X,Y] = ndgrid(1:100,1:100);

% Ground Truth image
Circle= zeros(100); Circle((X-50).^2 + (Y-50).^2 - 500 <= 0) = 1;

% Test image (parameterised by threshold)
pkg load statistics % if using octave - needed for 'mvnpdf'
pkg load image      % if using octave - needed for 'mat2gray'
Gaussian = mvnpdf([X(:), Y(:)], [45, 45], [500,0;0,500]);
Gaussian = reshape(Gaussian, size(X));
Gaussian = mat2gray(Gaussian);

%% Generate ROC curve for a range of thresholds
ThresholdRange = 0 : 0.025 : 1;
TPs = zeros(size(ThresholdRange));
FPs = zeros(size(ThresholdRange));
Ind = 0;
for Threshold = ThresholdRange 
  Ind = Ind + 1;
  TP = Circle .* (Gaussian > Threshold);
  T  = Circle;
  TPR = sum(TP(:)) / sum(T(:));
  TPs(Ind) = TPR;

  FP = (1 - Circle) .* (Gaussian > Threshold);
  N  = (1 - Circle);
  FPR = sum(FP(:)) / sum(N(:));
  FPs(Ind) = FPR;
end

%% Plotski curvski
plot(FPs, TPs, 'linewidth', 3, 'marker', 'o', 'markersize',10,'markeredgecolor', 'k', 'markerfacecolor', 'g');
hold on; 
plot(ThresholdRange, ThresholdRange, 'r-.', 'linewidth', 3);
axis([0,1,0,1]);
title('Les Curves du ROC! Ooh-la-la!', 'fontsize', 16);
xlabel('Le Rate des Positifs Falses! Oh mon dieu!', 'fontsize', 14);
ylabel('Le Rate des Positifs Vrais! Magnifique!', 'fontsize', 14);
grid on;

enter image description here

答案 1 :(得分:0)

感谢@TasosPapastylianou提供的评论。为了在绘图中获得更好的结果,我在x轴上对两个数组进行排序(或误差率)。再次感谢@TasosPapastylianou !!!