我想我会用一个不错的 ROC 曲线示例发布一个正确的答案,展示我们在 cmets 中讨论的内容:
%% 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;