how to make a roc curve on matlab
6 ビュー (過去 30 日間)
古いコメントを表示
I want to generate a ROC curve for the data in the attached excel sheet. I am using the following code:
meanthresh = 0.8:0.1:2.5; % This alters the mean threshold between 0.8 and 2.5 by 0.1
%% Beginning the Mean ROC
for a = 1:length(meanthresh) %% the for loop makes it to where the threshold is automatically altered and you do not have to do it manually
positive_a = meanthresh(a) < (prelimdataforROCs(:, 3)); % declaring an algorithm to determine if the value is greater than the threshold
true = prelimdataforROCs(:, 1) == 1; %true = if the data in the column is equal to (==) 1
false = prelimdataforROCs(:, 1) == 0; %false = if the data in the column is equal to (==) 0
TP = sum(positive_a(true)); %true positive = if both the true statement (true) and the positive statement (positive_a) are met, then sum all the true values
FP = sum(positive_a(false)); %false positive = if both the false statement (false) and the positive statement (positive_a) are met, then sum all the false values
FN = sum(true) - TP; %false negative = sum of all true values minus the true positives
TN = sum(false) - FP; %true negative = sum of all false values minus the false positives
sensitivity_a(a) = (TP/(TP+FN)); %%sensitivity equation
specificity_a(a) = (TN/(TN+FP)); %%specificity equation
end %% end of for loop
stdevthresh = 0:0.1:1.7; %This alters the st dev threshold from 0 to 1.7 by 0.1
% Beginning of St Dev ROC
for b = 1:length(stdevthresh)
positive_b = stdevthresh(b) < (prelimdataforROCs(:, 4)); % declaring an algorithm to determine if the value is greater than the threshold
true = prelimdataforROCs(:, 1) == 1; %true = if the data in the column is equal to (==) 1
false = prelimdataforROCs(:, 1) == 0; %false = if the data in the column is equal to (==) 0
TPsd = sum(positive_b(true)); %true positive = if both the true statement (true) and the positive statement (positive_b) are met, then sum all the true values
FPsd = sum(positive_b(false)); %false positive = if both the false statement (false) and the positive statement (positive_b) are met, then sum all the false values
FNsd = sum(true) - TPsd; %false negative = sum of all true values minus the true positives
TNsd = sum(false) - FPsd; %true negative = sum of all false values minus the false positives
sensitivity_b(b) = (TPsd/(TPsd+FNsd)); %%equations for sensitivity and specificity
specificity_b(b) = (TNsd/(TNsd+FPsd));
end
plot(1-specificity_b, sensitivity_b, 'Marker', '.', 'MarkerSize', 16, 'LineWidth', 1); %%this is the standard deviation plot
hold on %%allows more than one graph to be on the same plot--must be followed by "hold off" when done
plot(1-specificity_a, sensitivity_a, 'Marker', '.', 'MarkerSize', 24, 'LineWidth', 1); %%plotting command for the mean ROC
hold off
legend('St. Devs', 'Averages'); %%this puts a legend on the graph--legend('first name', 'second name')
xlabel('False Positive Rate'); %%label on x axis
ylabel('True Positive Rate'); %%label on y axistitle('ROC for Mean Path Length'); %%title of graph
But I am getting the following error: "Undefined operator '<' for input arguments of type 'table'."
Can you please tell me where I am going wrong?
0 件のコメント
採用された回答
Meg Noah
2020 年 1 月 6 日
I was able to run a slightly modified version with no errors. I do not know if it is doing what you want it to do.
% I want to generate a ROC curve for the data in the attached excel sheet. I am using the following code:
meanthresh = 0.8:0.1:2.5; % This alters the mean threshold between 0.8 and 2.5 by 0.1
rocTable = readtable('prelim data for ROCs.xlsx','range','$A3:$D18');
%% Beginning the Mean ROC
for a = 1:length(meanthresh) %% the for loop makes it to where the threshold is automatically altered and you do not have to do it manually
positive_a = meanthresh(a) < (rocTable.Average); % declaring an algorithm to determine if the value is greater than the threshold
true = rocTable.FID == 1; %true = if the data in the column is equal to (==) 1
false = rocTable.FID == 0; %false = if the data in the column is equal to (==) 0
TP = sum(positive_a(true)); %true positive = if both the true statement (true) and the positive statement (positive_a) are met, then sum all the true values
FP = sum(positive_a(false)); %false positive = if both the false statement (false) and the positive statement (positive_a) are met, then sum all the false values
FN = sum(true) - TP; %false negative = sum of all true values minus the true positives
TN = sum(false) - FP; %true negative = sum of all false values minus the false positives
sensitivity_a(a) = (TP/(TP+FN)); %%sensitivity equation
specificity_a(a) = (TN/(TN+FP)); %%specificity equation
end %% end of for loop
stdevthresh = 0:0.1:1.7; %This alters the st dev threshold from 0 to 1.7 by 0.1
% Beginning of St Dev ROC
for b = 1:length(stdevthresh)
positive_b = stdevthresh(b) < (rocTable.SD); % declaring an algorithm to determine if the value is greater than the threshold
true = rocTable.FID == 1; %true = if the data in the column is equal to (==) 1
false = rocTable.FID == 0; %false = if the data in the column is equal to (==) 0
TPsd = sum(positive_b(true)); %true positive = if both the true statement (true) and the positive statement (positive_b) are met, then sum all the true values
FPsd = sum(positive_b(false)); %false positive = if both the false statement (false) and the positive statement (positive_b) are met, then sum all the false values
FNsd = sum(true) - TPsd; %false negative = sum of all true values minus the true positives
TNsd = sum(false) - FPsd; %true negative = sum of all false values minus the false positives
sensitivity_b(b) = (TPsd/(TPsd+FNsd)); %%equations for sensitivity and specificity
specificity_b(b) = (TNsd/(TNsd+FPsd));
end
plot(1-specificity_b, sensitivity_b, 'Marker', '.', 'MarkerSize', 16, 'LineWidth', 1); %%this is the standard deviation plot
hold on %%allows more than one graph to be on the same plot--must be followed by "hold off" when done
plot(1-specificity_a, sensitivity_a, 'Marker', '.', 'MarkerSize', 24, 'LineWidth', 1); %%plotting command for the mean ROC
hold off
legend('St. Devs', 'Averages'); %%this puts a legend on the graph--legend('first name', 'second name')
xlabel('False Positive Rate'); %%label on x axis
ylabel('True Positive Rate'); %%label on y axistitle('ROC for Mean Path Length'); %%title of graph
% But I am getting the following error: "Undefined operator '<' for input arguments of type 'table'."
% Can you please tell me where I am going wrong?
The resulting image is:
5 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Sequence and Numeric Feature Data Workflows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!