From: Tom on
Hi,

I am following the example on how to use crossval with decision trees:

http://www.mathworks.com/products/statistics/demos.html?file=/products/demos/shipping/stats/classdemo.html

I follow the code examples, but when I execute:

dtclass = t.eval(meas(:,1:2));
bad = ~strcmp(dtclass,species);
dtResubErr = sum(bad) / N

dtClassFun = @(xtrain,ytrain,xtest)(eval(classregtree(xtrain,ytrain),xtest))
;
dtCVErr = crossval('mcr',meas(:,1:2),species, ...
'predfun', dtClassFun,'partition',cp)

I get a Function Handle Error

??? Error using ==> crossval at 102
FUN must be a function handle.

I have tried various ways around, but no luck. - Any suggestions.

Regards,
Tom
From: Alan Weiss on
I just tried running this, and had no problems. Try executing
echodemo classdemo
See if you get through the demo OK. If not, try restarting MATLAB and
then running the echodemo again.

Alan Weiss
MATLAB mathematical toolbox documentation

On 6/22/2010 8:17 AM, Tom wrote:
> Hi,
>
> I am following the example on how to use crossval with decision trees:
>
> http://www.mathworks.com/products/statistics/demos.html?file=/products/demos/shipping/stats/classdemo.html
>
>
> I follow the code examples, but when I execute:
>
> dtclass = t.eval(meas(:,1:2));
> bad = ~strcmp(dtclass,species);
> dtResubErr = sum(bad) / N
>
> dtClassFun =
> @(xtrain,ytrain,xtest)(eval(classregtree(xtrain,ytrain),xtest))
> ;
> dtCVErr = crossval('mcr',meas(:,1:2),species, ...
> 'predfun', dtClassFun,'partition',cp)
>
> I get a Function Handle Error
>
> ??? Error using ==> crossval at 102
> FUN must be a function handle.
>
> I have tried various ways around, but no luck. - Any suggestions.
>
> Regards,
> Tom

From: Ilya Narsky on
Alan Weiss wrote:
> I just tried running this, and had no problems. Try executing
> echodemo classdemo
> See if you get through the demo OK. If not, try restarting MATLAB and
> then running the echodemo again.
>
> Alan Weiss
> MATLAB mathematical toolbox documentation
>
> On 6/22/2010 8:17 AM, Tom wrote:
>> Hi,
>>
>> I am following the example on how to use crossval with decision trees:
>>
>> http://www.mathworks.com/products/statistics/demos.html?file=/products/demos/shipping/stats/classdemo.html
>>
>>
>>
>> I follow the code examples, but when I execute:
>>
>> dtclass = t.eval(meas(:,1:2));
>> bad = ~strcmp(dtclass,species);
>> dtResubErr = sum(bad) / N
>>
>> dtClassFun =
>> @(xtrain,ytrain,xtest)(eval(classregtree(xtrain,ytrain),xtest))
>> ;
>> dtCVErr = crossval('mcr',meas(:,1:2),species, ...
>> 'predfun', dtClassFun,'partition',cp)
>>
>> I get a Function Handle Error
>>
>> ??? Error using ==> crossval at 102
>> FUN must be a function handle.
>>
>> I have tried various ways around, but no luck. - Any suggestions.
>>
>> Regards,
>> Tom
>

In addition to what Alan said, I'd like to point out that classregtree
has a built-in method for cross-validation. Do 'help classregtree/test'.
Your choice however is limited to 10-fold cross-validation. -Ilya