问题
If I have a matrix A of size m x n. The elements in the matrix represent the results of a specific detector.
What I want is to characterize the performance of the detector by an ROC curve (sensitivity or Probability of detection by function of the probability of False alarm or 1-specificity). Interestingly, when (A(i,j) >= threshold) => the target is present, else it is absent. But of course, there will be some errors like as False alarm (False Positive) or Miss (False Negative).
Lets first remember of two important equations:
Sensitivity = Probability of detection = TruePositive / (TruePositive + FalsePositive).
1-Specificity = Probability of False Alarm = TruePositive / (TruePositive + FalseNegative).
Now, I will give you what I tried to write in MATLAB, but what I want to know is how can I write both sections 1) and 2) of the code below in order to be able to draw a certain roc curve.
My MATLAB code:
clear all;
close all;
clc;
NumOperation = 1; % the number of operation to be achieved will increase by 1 for new value of Threshold.
for Threshold = a:1:b; % So the threshold can take the values arranged from "a" to "b".
Thresholding_result = zeros (m, n); % It is the matrix that will contain either zero (if the detection result in A is below a certain threshold) or 1 (if the detection result in A is above the threshold).
Thresholding_result (find(A > Threshold)) = 1; % So the zero elements in the Thresholding_result matrix will be transformed to 1 when the corresponding values in A are above the Threshold.
TruePositive = 0;
FalsePositive = 0;
TrueNegative = 0;
FalseNegative = 0;
for i = 1 : m
for j = 1 : n
if (Thresholding_result(i,j) == 1)
% 1) so if we have 1, then there will be two options: either the target is really present ==> increasing the TruePositive by 1 (TruePositive = TruePositive + 1), or is not ==> increasing the FalsePositive by 1 (FalsePositive = FalsePositive + 1).
end
else if (Thresholding_result(i,j) == 0)
% 2) so if we have 0, then there will be two options: either the target is really not present ==> increasing the TrueNegative by 1 (TrueNegative = TrueNegative + 1), or is not ==> increasing the FalseNegative by 1 (FalseNegative = FalseNegative + 1).
end
end
end
TP_Matrix(NumOperation) = TruePositive / (TruePositive + FalseNegative);
FP_Matrix(NumOperation) = TruePositive / (TruePositive + True Negative);
NumOperation = NumOperation + 1;
end
% Plotting the ROC curve:
Plot((FP_Matrix), (TP_Matrix), 'b-'), xlabel('False Alarm'), ylabel('Probability of Detection');
Any help will be very appreciated!
来源:https://stackoverflow.com/questions/30211461/plotting-the-roc-curve