"trainNetwork" says invalid training data
    8 views (last 30 days)
  
       Show older comments
    
I am new to neural netwroks. I have succeeded in training a shallow neural network using input data of 500*5 dimension that is each of 500 data points has 5 features to predict Y values (regression). I used- 
net = train(net,X,Y);     for shallow training which worked just fine.
But now when I am trying to train using deep learning with "trainNetwork" like this-
net = trainNetwork(X,Y,layers,options);    MATLAB throws an error like this-
Invalid training data. Predictors must be a N-by-1 cell array of sequences, where N is the number of sequences. All sequences must have the same feature dimension and at least one time step.
Where am I going wrong? In each case I have passed input X as 500*5 double and output Y as column vector
0 Comments
Answers (1)
  Parag
 on 24 Jan 2025
        Hi,   
One possible error could be due to taking a transposed vector in your code.  Please check the code for ‘train’ for shallow training and using ‘trainNetwork’. It is working for me; 
% Generate dummy data
numSamples = 500;
numFeatures = 5;
% Random input data
X = rand(numSamples, numFeatures);
% Random target values (for regression)
Y = rand(numSamples, 1);
% Create and configure a shallow neural network
shallowNet = feedforwardnet(10); % Example with 10 hidden neurons
% Train the shallow network
shallowNet = train(shallowNet, X', Y'); % Note the transpose to match input dimensions
% Define the layers for a deep learning model
layers = [
    featureInputLayer(numFeatures)  % 5 features
    fullyConnectedLayer(10)         % Example hidden layer
    reluLayer                       % Activation layer
    fullyConnectedLayer(1)          % Output layer for regression
    regressionLayer                 % Regression layer
];
% Set training options
options = trainingOptions('adam', ...
    'MaxEpochs', 100, ...
    'MiniBatchSize', 32, ...
    'Plots', 'training-progress');
% Train the deep network
deepNet = trainNetwork(X, Y, layers, options);
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
