"Index in position 2 exceeds array bounds (must not exceed 1)" with machine learning

1 view (last 30 days)
Purpose: I am a beginner of machine learning that seeks to use neural network and large number of predictors to predict values.
Problem: When I attempted to follow the sample from other cases from Matlab answers, the result won't allow me to train the data. Instead, it kept telling me "Index in position 2 exceeds array bounds (must not exceed 1)" with machine learning
Code Used:
%Q and S are imported time series; Q is the predictor variable and S is the targed variable
Sn = (S-min(S))/(max(S)-min(S));%normalizing S, 7670x1 Double
Qn = (Q-min(Q))/(max(Q)-min(Q));%normalizing Q, 7670x1 Double
trainFcn ='trainlm';
%Train my data with Narxnet
hiddenLayerSize = 10
N = 7671
inputDelays = 5
feedbacksDelays = 5
net = narxnet(1:inputDelays, 1:feedbacksDelays,hiddenLayerSize);
[Xs,Xi,Ai,Ts] = preparets(net,Sn,{},Qn);

Answers (1)

Srivardhan Gadila
Srivardhan Gadila on 15 Jul 2020
As per my understanding after referring to train - Input Arguments & preparets, I think the network inputs & targets must be a cell array and not matrix in case of time series data. Also the shape of the cell array should be according to the documentation, refer to the example of narxnet to understand the shape of X & T i.e., input & target.
In your above code Sn & Qn are 7670x1 Double, try changing them to cell array of shape 1x7670. The following code might help you:
Sn = num2cell(randn(7670,1)');
Qn = num2cell(randn(7670,1)');
trainFcn ='trainlm';
%Train my data with Narxnet
hiddenLayerSize = 10
N = 7671
inputDelays = 5
feedbacksDelays = 5
% net = narxnet(1:inputDelays, 1:feedbacksDelays,hiddenLayerSize);
net = narxnet(1:5, 1:5,10);
[Xs,Xi,Ai,Ts] = preparets(net,Sn,{},Qn);

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!