Invalid training data. Predictors and responses must have the same number of observations. Multiple input layers, feature regression
Show older comments
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:
- 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).
- 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);
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox 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!