I'm working through the example code given by Matlab, but I can't seem to exactly reproduce the ROC curve that is plotted. I want to make sure I am understanding the thresholding concept properly. Could anyone help me to understand why the two figures plotted below are different?
clear; clc; load fisheriris; pred = meas(51:end,1:2); resp = (1:100)'>50; % Versicolor = 0, virginica = 1 mdl = fitglm(pred,resp,'Distribution','binomial','Link','logit'); scores = mdl.Fitted.Probability; [X,Y,T,AUC] = perfcurve(species(51:end,:),scores,'virginica'); figure; plot(X,Y); xlabel('False positive rate'); ylabel('True positive rate'); title('ROC , built-in'); tpr = nan(length(T),1); fpr = nan(length(T),1); for ind_F = 1:1:length(T) t_true = scores >= T(ind_F); group = resp; grouphat = t_true; t_cm = confusionmat(group,grouphat); % ROC : TPR / FPR tpr(ind_F) = t_cm(1,1)/sum(t_cm(1,:)); fpr(ind_F) = t_cm(2,1)/sum(t_cm(2,:)); end figure; plot(fpr,tpr); xlabel('fpr'); ylabel('tpr'); title('ROC , derived');
Thanks for the help.