no. of samples while using 'train' for a neural network
2 views (last 30 days)
Show older comments
I am solving an 'Input-Output Time-Series Problem with a Time Delay Neural Network'.
I am getting an error in the statement-
[net,tr] = train(net,inputs,targets,inputStates,layerStates);
error-- 'Inputs and targets have different numbers of samples'
the dimensions of the various variable are--
inputStates = 1*2 cell
inputs= 1*59 cell
layerStates=1*2 cell
targets=1*59 cell.
Also each column of 'inputs' cell array is a vector of 5 double values. i.e using 5 features of a problem we are predicting a target value. number of timestamps=61, input delays=2.
I dont why is the error??? inputs and targets shows the same dimensions in workspace too..
2 Comments
Accepted Answer
Greg Heath
on 23 Nov 2014
I ran your code with the pollution_dataset.
The same error occurred until I placed the code after the plot function continuation symbol "..." on the next line.
I have several suggestions which are exemplified in the following code that takes advantage of defaults:
close all, clear all, clc
[ X, T ] = pollution_dataset; % MIMO
x = cell2mat(X);
t = cell2mat(T);
whos
% Name Size Bytes Class
% T 1x508 69088 cell
% X 1x508 89408 cell
% t 3x508 12192 double
% x 8x508 32512 double
[I N ] = size(x) % [ 8 508 ]
[O N ] = size(t) % [ 3 508 ]
% Avoid overfitting: Choose H <= Hub
Hub = -1+ ceil((0.7*N*O-O) / ( I+O+1)) % 88
ID = 0:2, H = 10 % DEFAULT
net = timedelaynet(ID,H);
[ Xs Xi Ti Ts ] = preparets(net,X,T);
ts = cell2mat(Ts);
MSE00s = mean(var(ts',1)) % 102.62
net.divideFcn = 'divideblock';
Ntrials = 10
rng('default')
for i=1:Ntrials
net = configure(net,Xs,Ts);
[ net tr Ys Es Xf Af ] = train(net,Xs,Ts,Xi,Ti);
% NOTE: outputs = Ys and errors = Es;
R2(i,1) = 1 - mse(Es)/MSE00s;
R2trn(i,1) = 1 - mse(Es(:,tr.trainInd))/MSE00s;
R2val(i,1) = 1 - mse(Es(:,tr.valInd))/MSE00s;
R2tst(i,1) = 1 - mse(Es(:,tr.testInd))/MSE00s;
end
result = [(1:Ntrials)' R2 R2trn R2val R2tst ]
% result =
%
% 1 0.5936 0.63533 0.51213 0.47697
% 2 0.67104 0.7206 0.60579 0.50104
% 3 0.58657 0.73979 0.50454 -0.058704
% 4 0.63051 0.69725 0.60746 0.3368
% 5 0.48704 0.65898 0.34343 -0.1855
% 6 -0.016047 0.66023 0.4646 -3.7067
% 7 0.49035 0.58225 0.54201 0.0025204
% 8 0.54354 0.53697 0.58071 0.53752
% 9 0.60964 0.61695 0.56824 0.61634
% 10 0.61471 0.63631 0.63058 0.49629
% Possible Improvements
% 1. Check for outlier removal
% 2. Choose ID w.r.t input/target crosscorrelations
% 3. Use narxnet and FD w.r.t. target autocorrelations
% 4. Increase H (Hub = 88)
0 Comments
More Answers (0)
See Also
Categories
Find more on Define Shallow Neural Network Architectures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!