Clear Filters
Clear Filters

get prediction of all binary learners for multi-class classification

2 views (last 30 days)
When I use fitcecoc to perform multi-category classification, kfordpredict function only give me the Yhat after error correcting(pool results from all binary learners), how can I see raw results for all binary learners within the model?

Accepted Answer

Aditya Patil
Aditya Patil on 16 Feb 2021
You can get the underlying compact models using the Trained Property. You can call the predict function on these models.
You can also get the binary learners from the compact models, as shown in the Inspect Binary Learner Properties of ECOC Classifier example. You will have to reimplement the Error-Correcting Output Codes Model if you want to aggregate the results. If not, you can pass the input data to the binary classifiers, and get the required result.
Here is an basic code example
load fisheriris
X = meas(:,3:4);
Y = species;
CVMdl = fitcecoc(X,Y, 'CrossVal',"on");
cvsize = size(CVMdl.Trained, 1);
for i = 1:cvsize
trainedMdl = CVMdl.Trained{i};
blsize = size(trainedMdl.BinaryLearners, 1);
for j = 1:blsize
blmdl = trainedMdl.BinaryLearners{j};
yhat = predict(blmdl, X);
% postprocess the yhat as required
end
end
Note that crossvalidated models are intended to be used for validating the accuracy of the model, and not for prediction in general.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!