MATLAB Answers


edit-error in classifier

Asked by FIR
on 12 Apr 2012
Accepted Answer by Ilya

I have a code

    y = species;
    X = meas;
    cp = cvpartition(y,'k',10); % Stratified cross-validation
    classf = TreeBagger(10,meas,species,'oobpred','on'); 
    cvMCR = crossval('mcr',X,y,'predfun',classf,'partition',cp)

i get error as

    Undefined function 'func2str' for input arguments of type 'TreeBagger'.
    Error in crossval>evalFun (line 465)
            error(message('stats:crossval:FunError', func2str( fun ), ME.message));




No products are associated with this question.

2 Answers

Answer by Ilya
on 12 Apr 2012
 Accepted answer


In particular, 2nd example for crossval here shows what you need to do. You would need to replace the function handle classf in that example with a function which has two lines of code in it: 1) Train a TreeBagger on Xtrain and Ytrain, and 2) Predict labels for Xtest using the trained TreeBagger.


Answer by Walter Roberson
on 12 Apr 2012

The 'predfun' parameter expects a function handle as the associated value. Instead you passed in a TreeBagger object.

  1 Comment

on 12 Apr 2012

walter can u please tell what to pass

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!