Dear All;
i am trying to use divide my data using Cvpartition with "Kfold" option in order to use for cross valdtion in neural network, i have a function to do that as shown below , it works but it give a warning message and i do not know why it is coming
Warning: One or more folds do not contain points from all the groups.
> In internal.stats.cvpartitionImpl>stra_kfoldcv (line 364)
In internal.stats.cvpartitionImpl/rerandom (line 315)
In internal.stats.cvpartitionInMemoryImpl (line 166)
In cvpartition (line 175)
In jFFNN_REG (line 14)
In NN_Kfold_Regression (line 8)
Function:
function [FFNN,Pred,Actual]=jFFNN_REG(input,output,kfold,Hiddens,Maxepochs)
% Layer
if length(Hiddens)==1
h1=Hiddens(1); net=fitnet(h1);
elseif length(Hiddens)==2
h1=Hiddens(1); h2=Hiddens(2); net=fitnet([h1 h2]);
elseif length(Hiddens)==3
h1=Hiddens(1); h2=Hiddens(2);
h3=Hiddens(3); net=fitnet([h1 h2 h3]);
end
%rng('default');
% Divide data into k-folds
fold=cvpartition(output,'kfold',kfold);
% Pre
pred2=[]; ytest2=[]; Afold=zeros(kfold,1);
% Neural network start
for i=1:kfold
% Call index of training & testing sets
trainIdx=fold.training(i); testIdx=fold.test(i);
% Call training & testing inputures and labels
xtrain=input(trainIdx,:); ytrain=output(trainIdx);
xtest=input(testIdx,:); ytest=output(testIdx);
% Set Maximum epochs
net.trainParam.epochs= Maxepochs;
% Training model
net=train(net,xtrain',ytrain');
% Perform testing
pred=net(xtest');
% Perfomance
tstPerform = perform(net, ytest', pred);
% Get accuracy for each fold
Afold(i)=tstPerform;
% Store temporary result for each fold
pred2=[pred2(1:end,:),pred]; ytest2=[ytest2(1:end);ytest];
end
Best Answer