Hi Pedro,
To create a ROC curve and determine the cutoff points for better significance, you can follow these steps:
- Calculate the True Positive Rate (TPR) and False Positive Rate (FPR) for different cutoff points:
- Calculate the True Positive Rate (TPR) and False Positive Rate (FPR) for different cutoff points. Start by sorting, set an initial cutoff point at the maximum predicted probability.
- Calculate the TPR and FPR for this cutoff point.
- Move the cutoff point to the next predicted probability and repeat the calculation until you reach the minimum predicted probability.
- Store the TPR and FPR values for each cutoff point.
2. Plot the ROC curve:
- Once you have the TPR and FPR values for different cutoff points, plot the ROC curve.
- The diagonal line from (0, 0) to (1, 1) represents a random classifier.
- The further the ROC curve is from the diagonal line, the better the classifier.
Here's an example of how you can create a ROC curve in MATLAB using your data:
% Convert the data from tables to arrays
pred = table2array(pred);
resp = table2array(resp);
% Calculate the False Positive Rate (FPR) and True Positive Rate (TPR)
% Plot the ROC curve
figure;
plot(1, 1);
hold on;
plot(0, 0);
[x, y, ~, ~] = perfcurve(resp, pred, 1);
plot(x, y, 'LineWidth', 2);
xlabel('False Positive Rate');
ylabel('True Positive Rate');
title('Receiver Operating Characteristic');
legend('Random Classifier', 'ROC curve');
hold off;
The “perfcurve” function is used to calculate the ROC curve. The function returns the False Positive Rate (FPR) and True Positive Rate (TPR) values, which are then plotted using the “plot” function.
Attached below are some documentation links that you may find helpful:
- Receiver operating characteristic (ROC) curve or other performance curve for classifier output - MATLAB perfcurve (mathworks.com)
- Receiver operating characteristic - Wikipedia
- (244) ROC Curves - YouTube
Hope this helps!
Karan Singh Khati