Using the fuzzy toolbox in Matlab, i try to calculate the error on the validation set. First cross validation is used to split the initial training data in a training and test (validation) set. However in this validation phase I would like to obtain the error also for different parameter setting in the genfis3 function. I would like to vary the fourth input in this function from 2 to 10 and calculate the mean errors.
fismat3 = genfis3(X1,Y1,'sugeno',2);
The entire code:
[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)