MATLAB: Use trainnetwork for normal regression

deep learningregression

Hi,
I have a dataset of 63 inputs and 1 output for a regression problem. Total sample 39686.
X: 63×39686
Y: 1×39686
I can easily use "net=fitnet(…)" and "train(net X,Y)" to train the model.
But I want to try the trainnetwork function. After configuring the layers like this:
layers = [
sequenceInputLayer(size(X,1),"Name","sequence_In","Normalization","rescale-zero-one")
fullyConnectedLayer(20,"Name","fc_1")
fullyConnectedLayer(20,"Name","fc_2")
regressionLayer("Name","regressionoutput")];
and options:
options = trainingOptions('sgdm', …
'InitialLearnRate',0.001, …
'Verbose',false, …
'Plots','training-progress');
Then I train the model:
net = trainNetwork(X,Y,layers,options);
But it always shows :
To RESHAPE the number of elements must not change.
Error in NN_training_deep (line 33)
net = trainNetwork(X_,Y',layers,options);
Does anyone know how to solve this problem?

Best Answer

The outputSize argument for the fullyConnectedLayer before the regressionLayer must be 1 as the number of ouputs for your regression problem is 1.
layers = [
sequenceInputLayer(size(X,1),"Name","sequence_In","Normalization","rescale-zero-one")
fullyConnectedLayer(20,"Name","fc_1")
fullyConnectedLayer(20,"Name","fc_2")
fullyConnectedLayer(1,"Name","fc_3")
regressionLayer("Name","regressionoutput")];