How do you obtain a vector of predicted classes generated after cross-valiation of a decision tree?
Show older comments
I have created a decision tree (T) to predict classes, Y, based on features X. I would like to cross-validate the decision tree. When I do so, I can only get the overall cross-validation error, not the vector of classes as they are predicted from the cross-validation.
Here is the code I am trying to use: T3 = classregtree(X,Y,'method','classification'; view(T3); cp = cvpartition(Y,'k',10);
dtClassFun = @(xtrain,ytrain,xtest)(eval(classregtree(xtrain,ytrain),xtest));
crossvalerrorrT = crossval('mcr',X,Y,'predfun',dtClassFun,'partition',cp)
This will output a scalar overall cross-validation error.
How can I output a vector of cross-validation predicted classes (so that I can look at cross-validation error for each class separately)?
Accepted Answer
More Answers (1)
Ilya
on 29 Mar 2012
If you have 11a or later, you can use ClassificationTree:
load fisheriris;
cvtree = ClassificationTree(meas,species,'kfold',10);
Yfit = kfoldPredict(cvtree);
Categories
Find more on Classification Ensembles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!