# fitglm and ROC curves

11 visualizzazioni (ultimi 30 giorni)
PEDRO ALEXANDRE Fernandes il 22 Giu 2022
Risposto: Karan Singh il 29 Set 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);
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?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Karan Singh il 29 Set 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');
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.
Hope this helps!
Karan Singh Khati
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Dimensionality Reduction and Feature Extraction in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by