Duplicating categorical array to floating point value for perfcurve function

3 次查看(过去 30 天)
Hi, I am trying to generate an ROC curve for my data. The perfcurve function requires perfcurve(label,scores,posclass). My data has 2 labels, either AD or CN.
I have a categorical array called audsPreds which is my 'scores' in perfcurve as it is the predicted values from my neural network. audsActual is the actual values inputted which I am using for 'label' in perfcurve. I am using '1' as my posclass which should depict AD, not CN. I am having many issues with getting perfcurve to work. I don't know if my audsPreds and audsActual categorical arrays have to be changed so that AD reads 1 and CN reads 2. When I try to run the function it says 'scores' should be passed as floating point values.
I may have done more things incorrectly, please help.

回答(2 个)

Sharad
Sharad 2023-7-6
Hi,
As per my understanding, you are facing issues related to the proper formatting of the inputs for perfcurve function, due to which you are getting errors.
In order to get the proper results, you can follow these steps :
  • Convert your categorical arrays to numeric format (double() function can be used to obtain proper format for perfcurve function).
audsPredsNumeric = double(audsPreds == "AD") + 1;
audsActualNumeric = double(audsActual == "AD") + 1;
Here, the positive class is AD which reads 1, and the negative class is CN which reads 2.
  • Call the perfcurve function with the updated inputs.
[X, Y, ~, AUC] = perfcurve(audsActualNumeric, audsPredsNumeric, 1);
Here are some documentation links that you can follow :
Thank you.

Peter Perkins
Peter Perkins 2023-7-17
The short answer is that you can call double on a categorical array to get the category numbers as a numeric array. But that may not be the right answer.
The category numbers correspond to whatever order you see if you call categories on the categorical. You may have decided on that order or it may have happened automatically.
Or the numbers you may want may have come from numeric data that were converted to categorical at some point. Those numbers are not saved in the categorical array once you convert, you would need to have saved them yourself.

Community Treasure Hunt

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

Start Hunting!

Translated by