|
• Neural Networks
Hi Guys,
I have doubts regarding the cross validation like programming in Matlab such as doing a 10-fold validation so could you please give me some guide as in where I have gone wrong.
My codes are as followed:
Preprocess codes
load california_data.mat
Val.P = P_test; Val.T = T_test;
[P_train_n minp maxp] = premnmx(P_train);
Val_n.P = tramnmx(P_test,minp,maxp);
[T_train_n mint maxt] = premnmx(T_train);
Val_n.T = tramnmx(T_test,mint,maxt);
[P_train_std meanp stdp] = prestd(P_train);
Val_std.P = trastd(P_test,meanp,stdp);
[T_train_std meant stdt] = prestd(T_train);
Val_std.T = trastd(T_test,meant,stdt);
Training codes
%P_train = P_train_n; T_train = T_train_n; Val = Val_n; %%% Use this line to use mnmx preprocessing on the data. IMPORTANT: Run preprocess.m first
P_train = P_train_std; T_train = T_train_std; Val = Val_std; %%% Use this line to use STD preprocessing on the data. IMPORTANT: Run preprocess.m first
net = newff(minmax(P_train),[10 1],{'tansig','tansig'},'trainlm');
%net.trainParam.lr = -0.05;
%net.trainParam.goal = 0.5;
net = init(net);
net.trainParam.epochs =200;
net.trainParam.max_fail = 50;
[net tr] = train(net,P_train,T_train,[],[],Val);
[fields N] = size(T_test);
********** Please see here *****************
indices = crossvalind('Kfold',N,10);
for i = 1:10
test = (indices == i); train = ~test;
end
********************************************
est = sim(net,Val.P);
%est = postmnmx(est,mint,maxt); %%% Use this line if you use mnmx preprocessing on the data. IMPORTANT: Uncomment the corresponding line above
est = poststd(est,meant,stdt); %%% Use this line if you use STD or PCA preprocessing on the data. IMPORTANT: Uncomment the corresponding line above
RMS_Error = sqrt(mean((T_test - est).^2))
Many thanks and hope to hear from you.
Warmest Regards,
Jimmy.
|