I ask for your help regarding Kfold cross validation, I want to  determine the optimal training function of the neural network and the optimal number of neurons in the hidden layer.

I am trying to write code with matlab for optimization of culture conditions, I have 3 parameters as input and one target (Protease activity), with 1 hidden layers. I wrote a script but i think there is some thing wrong.

May you help me writting the true codes?

------------------------------------------------------------------------------------------------------------------------------------------

clc, clear

load ANNtest.mat;

kfold = 10;

fold=cvpartition(20,'kfold',kfold);

% Pre

pred2=[];predt2=[]; ytest2=[];ytrain2=[]; Afold=zeros(kfold,1); Bfold=zeros(kfold,1);

net=newff(input',target',[6],{'tansig' 'purelin'});

% 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=target(trainIdx);

xtest=input(testIdx,:);

ytest=target(testIdx);

net.trainFcn = 'trainlm' ;

net.performFcn = 'mse';

% Training model

net1 = train(net,xtrain',ytrain');

% Perform testing

predt=net1(xtrain');

pred=net1(xtest');

% Perfomance

trnPerform = perform(net1, ytrain', predt);

tstPerform = perform(net1, ytest', pred);

% Get accuracy for each fold

Afold(i)=tstPerform;

Bfold(i)=trnPerform;

% Store temporary result for each fold

pred2=[pred2(1:end,:),pred]; ytest2=[ytest2(1:end);ytest];

predt2=[predt2(1:end,:),predt]; ytrain2=[ytrain2(1:end);ytrain];

end

accuracy = mean(Afold);

More Fateh Merouane's questions See All
Similar questions and discussions