How to plot A smooth curve of ROC in MATLAB with only 3 FPR and TPR values

7 次查看(过去 30 天)
Hello All,
I have used a k-fold cross validation for my model in matlab. and for each fold i have used the following to create ROC curve:
[fpr,tpr,~,AUC] = perfcurve(Y_test,y_pred,1);
and after completing all the iterations for k-folds, I have taken the average fpr and average tpr values and tried to plot the roc curve using the following lines:
plot(avgfpr,avgtpr)
but the fpr and tpr values are calculated only with 3 thresholds with the perfcurve() and the values are as follows:
fpr=[0,0,1] and tpr=[0,0.875,1]
the resultant curve is as shown in the figure with straight line plot. can anyone helpme out in how to draw the curve smoothly?
Thanks in advance.

回答(1 个)

Drew
Drew 2023-10-26
Some pointers:
  • As a low-code alternative, the Classification Learner app will produce ROC plots.
  • As an alternative to perfcurve which was introduced in R2009a, rocmetrics https://www.mathworks.com/help/stats/rocmetrics.html was introduced in R2022a. rocmetrics produces an rocmetrics object which provides some additional funcitonality. The basic syntax is
rocObj = rocmetrics(Labels,Scores,ClassNames)
  • As seen in the basic rocmetrics syntax above, for each data observation, the necessary input includes the correct Label, the classifier Scores (for all classes), and the ClassNames. From what you have written, it is not clear if you have provided the classifer scores as input.
  • How many unique output classes are there in the classification problem? Keep in mind that the ROC curve is different for each class. That is, an ROC curve can be constructed for each class, with that class treated as one-vs-all, that is, that one class versus all other classes. If you have a binary problem, you just need to pick which class to consider as the "positive" class. If you have a multiclass problem, you can look at the one-vs-all ROC curve for each class, or as an alternative, the rocmetrics object also provides an "average" method to "Compute performance metrics for average receiver operating characteristic (ROC) curve in multiclass problem", see https://www.mathworks.com/help/stats/rocmetrics.average.html
  2 个评论
ARCHANA GUNAKALA
ARCHANA GUNAKALA 2023-10-30
i have provided the scores aslo. In the line perfcurve(Y_test,y_pred,1); Y_test are the class labels and y_pred are the scores and 1 is the positive class name( I have two classes in my data 1 and 0).
I even tried rocmetrics but the graph is plotted same as the perfcurve() function.
Drew
Drew 2023-10-30
Assuming all is configured correctly, then the ROC curve looks like that because the classifier is performing almost perfectly on the data. This extremely good performance could be "real", that is, a good prediction of performance on new unseen data, or it could be the result of problems such as the combination of overfitting and training on the test set. So, check that your training and test sets are properly distinct, etc.
The attached ROC.jpg that you provided is:

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Model Building and Assessment 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by