From: rocky on
>> clc
>> clear
%now i import a file from excel and give the matrix the name 'data'
%each row is a sample, each column is a attribute
>> input=data(:,1:13);
output=data(:,14);
[train,test]=crossvalind('holdout',output);
input_train=input(train,:);
output_train=output(train,:);
input_test=input(test,:);
output_test=output(test,:);
t=classregtree(input_train,output_train,'names',{'CRIM' 'ZN' 'INDUS' 'CHAS' 'NOX' 'RM' 'AGE' 'DIS' 'RAD' 'TAX' 'PTRATIO' 'B' 'LSTAT'});
>> [cost,s,n,best] = test(t,'cross',input_train,output_train);
??? Indexing cannot yield multiple results.
why have this problem, how can i solve it ?
From: Ilya Narsky on

"rocky " <rockyguojing(a)gmail.com> wrote in message
news:hevbla$bt4$1(a)fred.mathworks.com...
>>> clc
>>> clear
> %now i import a file from excel and give the matrix the name 'data'
> %each row is a sample, each column is a attribute
>>> input=data(:,1:13);
> output=data(:,14);
> [train,test]=crossvalind('holdout',output);
> input_train=input(train,:);
> output_train=output(train,:);
> input_test=input(test,:);
> output_test=output(test,:);
> t=classregtree(input_train,output_train,'names',{'CRIM' 'ZN' 'INDUS'
> 'CHAS' 'NOX' 'RM' 'AGE' 'DIS' 'RAD' 'TAX' 'PTRATIO' 'B' 'LSTAT'});
>>> [cost,s,n,best] = test(t,'cross',input_train,output_train);
> ??? Indexing cannot yield multiple results.
> why have this problem, how can i solve it ?

Can you try

cost = t.test('cross',input_train,output_train);

and let us know if it makes a difference?

Also, the subject line says "decision tree for regression", but looks like
your 'output' is categorical. If your 'output' is continuous, using
crossvalind is not a good idea. Perhaps, what you really want is a
classification tree. -Ilya