roc plot

7 Ansichten (letzte 30 Tage)
x am 23 Sep. 2011
Beantwortet: Sanchari am 25 Jul. 2024 um 3:47
area = roc(fileName,exp)
%
% fileName: The name of the output file. It is an image
% exp: a structure representing an experiment with three fields
% - exp.name: a string specifying the experiment name
% - exp.positive_n: the number of positive samples in the experiment
% - exp.likelihoods: likelihoods of each sample where the first
% exp.positive_n number of likelihoods belongs to the positive
% samples while others belong to the negative samples.
% area: a 1x1-dimensional cell array of the area under the roc curve.
true positive,false positive values of ground truth,edge detected image was calculated...then how apply these values to roc program...??????
0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sanchari am 25 Jul. 2024 um 3:47
Hello x,
To apply the true positive and false positive values to a ROC (Receiver Operating Characteristic) program, you need to follow these steps:
1. Calculate the True Positive Rate (TPR) and False Positive Rate (FPR): TPR (also known as sensitivity or recall) is the ratio of true positives to the sum of true positives and false negatives. FPR is the ratio of false positives to the sum of false positives and true negatives.
2. Generate the ROC curve: Plot the TPR against the FPR at various threshold settings.
3. Compute the Area Under the Curve (AUC): The AUC represents the degree or measure of separability. It tells how much the model is capable of distinguishing between classes.
Here's a sample MATLAB function that generates the ROC curve and computes the AUC based on the given "exp" structure.
function area = roc(fileName, exp)
% Extract the fields from the exp structure
positive_n = exp.positive_n;
likelihoods = exp.likelihoods;
% Sort likelihoods and corresponding labels
[sorted_likelihoods, sorted_indices] = sort(likelihoods, 'descend');
labels = [ones(positive_n, 1); zeros(length(likelihoods) - positive_n, 1)];
sorted_labels = labels(sorted_indices);
% Initialize TPR and FPR
TPR = zeros(length(likelihoods) + 1, 1);
FPR = zeros(length(likelihoods) + 1, 1);
% Calculate TPR and FPR for each threshold
for i = 1:length(likelihoods)
TP = sum(sorted_labels(1:i));
FP = i - TP;
TPR(i+1) = TP / positive_n;
FPR(i+1) = FP / (length(likelihoods) - positive_n);
end
% Plot the ROC curve
figure;
plot(FPR, TPR, '-');
xlabel('False Positive Rate');
ylabel('True Positive Rate');
title(['ROC Curve: ', exp.name]);
grid on;
% Save the ROC curve as an image
saveas(gcf, fileName);
% Compute the Area Under the Curve (AUC)
area = trapz(FPR, TPR);
% Return the AUC as a 1x1-dimensional cell array
area = {area};
end
To use this function, you need to prepare your exp structure with the true positive and false positive values calculated from your ground truth and edge-detected images. Here's an example usage of this function:
% Example data
exp.name = 'Example Experiment';
exp.positive_n = 50; % Number of positive samples
exp.likelihoods = rand(100, 1); % Random likelihoods for demonstration
% File name to save the ROC curve image
fileName = 'roc_curve.png';
% Call the roc function
area = roc(fileName, exp);
% Display the Area Under the Curve (AUC)
disp(['Area Under the ROC Curve: ', num2str(area{1})]);
Please consider checking out this File Exchange link for the same: https://in.mathworks.com/matlabcentral/fileexchange/21318-roc-curves-and-area-under-of-them
Hope this helps!
0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Detection finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by