绘制ROC曲线

时间:2015-05-13 09:58:39

标签: matlab plot signal-processing detection roc

如果我有一个大小为A的矩阵m x n。矩阵中的元素表示特定检测器的结果。

我想要的是通过ROC曲线表征检测器的性能(灵敏度或通过误报概率或1-特异性的功能检测的概率)。有趣的是,当(A(i,j) >= threshold) => the target is presentelse it is absent时。但是,当然会出现一些错误,如误报(误报)或错(假错)。

让我们先记住两个重要的方程式:

Sensitivity = Probability of detection = TruePositive / (TruePositive + FalsePositive).
1-Specificity = Probability of False Alarm = TruePositive / (TruePositive + FalseNegative).

现在,我将向您介绍我在MATLAB中编写的内容,但我想知道的是如何编写以下代码的1)2)部分以便能够绘制一条roc曲线。

我的MATLAB代码:

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');

非常感谢任何帮助!

0 个答案:

没有答案