Work out input classifier variable threshold in ROC analysis using perfcurve
1 view (last 30 days)
Show older comments
I am trying to work out the threshold value(s) for an input classifier variable X (or combination of variables) in a leave-one-out prediction model for Y (binary) using fitcdiscr, crossval, kfoldPredict, and perfcurve. I understand that I can work out the optimum threshold in the output distribition by searching for the optimum ROC point, but I am struggling to understand how I can then translate that back to understand what the threshold value(s) is/are in my input X. Any help would be most appreciated.
Here's my code...
mdl_xval = fitcdiscr(X,Y); %input variable X (can be more than one col) and response Y
cvmodel = crossval(mdl_xval,'Leaveout','on');
[label,score,cost] = kfoldPredict(cvmodel);
[X,Y,T,AUC,OPTROCPT,suby,subnames] = perfcurve(ycell,score(:,2),'+','NBoot',500); %perfomance metrics
T_thresh = T((X==OPTROCPT(1))&(Y==OPTROCPT(2))); %threshold value in distribution
0 Comments
Answers (1)
Shivansh
on 29 Aug 2023
Hi Thomas,
You can translate the optimum ROC point to find the threshold using the following steps. This solution is with assumption that you have found the coordinates of optimum ROC point for your analysis.
1. Find the index of the optimum ROC point with respect to ‘X’ and ‘Y’ vectors. The following line of code will help with it.
Index = find(X==opt_roc_point(1) & Y==opt_roc_point(2));
2. Retrieve the corresponding value(s) from ‘X’. You can use the following line of codes depending upon the data type of X.
If X is a single column data, directly retrieve the value from the index.
threshold = X(Index)
If X is a multi-column data, you can use the following line of code.
threshold = X(Index,:)
The threshold variable will hold the input classifier variable threshold for the data.
0 Comments
See Also
Categories
Find more on Discriminant Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!