How to know classification mean and standard deviation accuracy of a cross validated classifier?

8 views (last 30 days)
I am training a optimized decision tree classifier using the function 'fitctree' and cross validated it using 5 kFold. I wanted to know the accuracy of the classificaton for each fold, so that I can calculate the mean and the standard deviation of the accuracy of each fold. Is there any way to do that? I've been searching for a while and haven't found any answer. The closest answer that I was getting was using 'kfoldLoss', but I don't understand how it would correlate to the one that I asked. Here is my code.
Mdl = fitctree(x(:, [427, 195, 121, 120, 122, 80, 43, 83, 34, 411, 317, 276, 303, 68, 66, 441, 76, 50, 69]), y,'OptimizeHyperparameters','auto',...
'HyperparameterOptimizationOptions',struct('AcquisitionFunctionName','expected-improvement-plus'));
CVMdl = crossval(Mdl, 'kFold', 5);
Unrecognized function or variable 'x'.
x is the features and y is the output class. Thank you for your help in advance.

Answers (1)

Rohit
Rohit on 29 Aug 2023
I understand that you want to calculate the accuracy of the classification for each fold and then compute the mean and standard deviation.
To achieve this, you can follow these steps:
  1. Use the “crossval” function to perform k-fold cross-validation on your decision tree classifier model (Mdl). Set the number of folds to 5 using the “kFold” option.
  2. After cross-validation is complete, you can use the “kfoldPredict” function to obtain the predicted labels for each fold.
  3. Compare the predicted labels with the true labels (y) to calculate the accuracy for each fold.
  4. Calculate the mean and standard deviation of the accuracy values obtained from the previous step.
CVMdl = crossval(Mdl, 'kFold', 5);
% Perform k-fold cross-validation predictions
kfold_pred = kfoldPredict(CVMdl);
You can refer to these documentation links for further reference:

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!