嵌套循环模糊逻辑验证

时间:2016-01-24 15:51:53

标签: matlab validation loops fuzzy

在Matlab中使用模糊工具箱,我尝试计算验证集上的错误。第一次交叉验证用于在训练和测试(验证)集中分割初始训练数据。但是在此验证阶段,我还想获得genfis3函数中不同参数设置的错误。我想将此函数中的第四个输入从2改为10并计算平均误差。

fismat3 = genfis3(X1,Y1,'sugeno',2);

整个代码:

 [m,~]=size(dataTrain);
    CVO = cvpartition(m,'k',10);
    err = zeros(CVO.NumTestSets,1);

    for i = 1:CVO.NumTestSets
     trIdx = CVO.training(i);
     teIdx = CVO.test(i);
     X1=Xtrain(trIdx,:);
     X2=Xtrain(teIdx,:);
     Y1=Ytrain(trIdx,:);
     Y2=Ytrain(teIdx,:);

     fismat3 = genfis3(X1,Y1,'sugeno',2);
     fismat3 = anfis([X1,Y1],fismat3);
     out1=evalfis(X2,fismat3);
     ee=Y2-out1;
     err(i)=mean(abs(ee));
end
Error32 = mean(err)

1 个答案:

答案 0 :(得分:0)

想出来:

[m,~]=size(dataTrain);
CVO = cvpartition(m,'k',10);
err = zeros(CVO.NumTestSets,9);%9 denotes the amount of different parameter setting you want to validate
out = zeros(CVO.NumTestSets,1);
ee = zeros(CVO.NumTestSets,1);
for i = 1:CVO.NumTestSets %voor iedere test en training set
     trIdx = CVO.training(i); %selecteer index training data
     teIdx = CVO.test(i); %selecteer index test data
     X1=Xtrain(trIdx,:); %Creer training input variabelen
     X2=Xtrain(teIdx,:); %Creer test input variabelen
     Y1=Ytrain(trIdx,:); % Creer training output variable
     Y2=Ytrain(teIdx,:); % Creer test output variable

for j = 2:10     
     fismat3 = genfis3(X1,Y1,'sugeno',j); %creer voor iedere test en training set een andere genfis 3
     fismat3 = anfis([X1,Y1],fismat3); %optimaliseer using anfis
     out1=evalfis(X2,fismat3);          
     ee=Y2-out1;
     err(i,j-1)=mean(abs(ee));
end

end

Error = mean(err)