Filter löschen
Filter löschen

Invalid training data. Predictors and responses must have the same number of observations. Multiple input layers, feature regression

2 Ansichten (letzte 30 Tage)
I got an error 'Invalid training data. Predictors and responses must have the same number of observations.', when I tried to train my regression DNN network.
My questions are following:
  1. I don't know how to make input set(X) in the case of multiple input layer of feature input(not image or sequence input). It is explained that Datastore is used for multiple input layers, but I don't know how to get Datastore from my two input arrays(X1, X2).
  2. The number of samples are equal for all data(X1, X2, Y). But I don't know why the error says they have unequal number of samples(observations)
The code is attached below
% X1: num_samples x feature1 array
% X2: num_samples x feature2 array (feature2 = 1)
% Y: num_samples x 1
X = cell(1, 2);
X{1} = X2;
X{2} = X1;
%% multiple input layers
lgraph = layerGraph();
tempLayers = featureInputLayer(1,"Name","featureinput_2");
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
featureInputLayer(size(X1, 2),"Name","featureinput_1")
fullyConnectedLayer(128,"Name","fc0")
tanhLayer("Name","act0")
fullyConnectedLayer(64,"Name","fc1")
tanhLayer("Name","act1")
fullyConnectedLayer(32,"Name","fc2")
tanhLayer("Name","act2")
fullyConnectedLayer(12,"Name","fc3")
tanhLayer("Name","act3")
fullyConnectedLayer(4,"Name","fc4")
tanhLayer("Name","act4")
fullyConnectedLayer(1,"Name","fc5")
tanhLayer("Name","act5")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
multiplicationLayer(2,"Name","multiplication")
regressionLayer("Name","regressionoutput")];
lgraph = addLayers(lgraph,tempLayers);
clear tempLayers;
lgraph = connectLayers(lgraph,"featureinput_2","multiplication/in2");
lgraph = connectLayers(lgraph,"act5","multiplication/in1");
options = trainingOptions('adam', ...
'MiniBatchSize',128, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false, ...
'MaxEpochs', 10000);
net = trainNetwork(X,Y,lgraph,options);

Akzeptierte Antwort

Dinesh
Dinesh am 28 Mai 2023
Hi YoungSeo!
I have tried to reproduce the issue on my end. The error “predictors and responses should have the same number of observations” might have occurred due to the dimensions of the input ‘Y’. Please make sure that the dimensions of 'Y' are correct. For example, if you have 5000 observations, then your 'Y' should be an array of size ‘5000 x 1’.
If you are using a numeric array as ‘X’ for ‘trainNetwork’, then you must specify the ‘responses’ argument. Alternatively, you can use ‘Datastore’ to train the neural network.
To create ‘Datastore’. Please refer to the following MATLAB documentation.
For more information and examples about ‘trainNetwork’ function refer to the following MATLAB documentation.
Hope this helps!
Thank you!!

Weitere Antworten (0)

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by