fitglm and ROC curves

4 visualizaciones (últimos 30 días)
PEDRO ALEXANDRE Fernandes
PEDRO ALEXANDRE Fernandes el 22 de Jun. de 2022
Respondida: Karan Singh el 29 de Sept. de 2023
Good afternoon everyone.
I have a problem. I want to create a ROC curve. I have a table with 560 rows and 1 column, where are 0 and 1 which I named FinalDatasetToCompare and said it was my pred class. Another table with 560 rows and a column with values equal to 0 and 1 which I named Original and have 260- > 0 and 260- > 1. I have been doing hypothesis tests but wanted to use the roc curve to detect cut-off points for a better degree of significance:
resp =
560×1 table
Var2
___
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
pred =
560×1 table
PStatus
_______
0
0
0
1
0
1
1
0
1
1
1
1
1
1
0
1
1
0
1
0
1
1
0
1
1
0
1
1
0
1
0
0
1
pred = FinalDatasetToCompare(:,"PStatus")
resp = Original_labels_from_images(:,"Var2");
respA = table2array(resp);
mdl = fitglm(pred,respA,"Distribution","binomial","Link","logit")
scores = mdl.Fitted.Probability;
[X,Y,T,AUC,OPTROCPT] = perfcurve(Original_labels_from_images(:,"Var2"),scores,"PStatus");
I make this code but its wrong..
Can anyone help me?

Respuestas (1)

Karan Singh
Karan Singh el 29 de Sept. de 2023
Hi Pedro,
To create a ROC curve and determine the cutoff points for better significance, you can follow these steps:
  1. 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:
Hope this helps!
Karan Singh Khati

Categorías

Más información sobre Descriptive Statistics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by