e= load('data')
k=5; f=12;
n=e.n(:,1:12);
data=n(randsample(1:length(n),length(n)),:);
truth=n(:,features+1);
c = cvpartition(truth,'KFold',k)
for i= 1:k
trIdx = c.training(i);
teIdx = c.test(i);
Model = fitcecoc(data(trIdx,:),truth(trIdx,:))
[class,s]= predict (Model,data(teIdx,:));
end
Model = fitcecoc(data(trIdx,:),truth(trIdx,:))在for循环完成任何迭代过程中类的模型缺失之后。
i.e
在1st iteration
期间,模型具有4个类名(因为我的数据最初为ha)但在2nd iteration
或其他迭代中,分类器会错过或忽略一个类别。
即给出[1 3 4]而不是[1 2 3 4]
@@ Hussain Ahmad,请检查有关K折交叉验证的内容,https://machinelearningmastery.com/k-fold-cross-validation