使用matlab对决策树进行交叉验证

时间:2017-03-15 09:03:12

标签: matlab decision-tree cross-validation

我对使用matlab进行决策树的交叉验证存在问题。

data_label={'Revenu','Propriete','Credit ','Classe'};


my_data={'Eleve','Superieur','Non','C1';
'Eleve','Superieur','Oui','C2';
'Eleve','Superieur','Non','C1';
'Eleve','Inferieur','Oui','C2';
'Moyen','Superieur','Non','C1';
'Moyen','Superieur','Oui','C2';
'Moyen','Inferieur','Non','C2';
'Moyen','Inferieur','Oui','C2';
'Faible','Inferieur','Non','C3';
'Faible','Inferieur','Oui','C3'}; 

这是交叉验证的代码:

indices = crossvalind('Kfold',my_data(:,end),10);
cp = classperf(my_data(:,end));
for i = 1:10
    test = (indices == i); train = ~test;
    class = classify(my_data(test,:),my_data(train,:),my_data(train,:));
    classperf(cp,class,test)
end
cp.ErrorRat

matlab给我回复此错误

    Index exceeds matrix dimensions.

Error in test (line 23)
    class = classify(my_data(tests,:),my_data(train,:),data_label(train,:));

0 个答案:

没有答案