I really need help about LSTM.

7 次查看(过去 30 天)
Nazila Pourhajy
Nazila Pourhajy 2021-10-15
回答: Asim 2024-10-23,19:17
Hi everyone.
I have a data set of 500*8 and I have 8 features for price prediction. I used LSTM to predict the price per hour of the day (a total of 24 prices for 24 hours a day). But I do not know how much output size should be for first fullyConnectedLayer after lstmLayer. please guide me. Thankful.
This is my code:
numResponses = size(YTrain{1},1);
featureDimension = size(XTrain{1},1);
numHiddenUnits = 15;
layers = [ ...
sequenceInputLayer(featureDimension)
lstmLayer(numHiddenUnits,'OutputMode','sequence')
fullyConnectedLayer(?????) %%50
dropoutLayer(0.5) %%0.5
fullyConnectedLayer(numResponses)
regressionLayer];

回答(1 个)

Asim
Asim 2024-10-23,19:17
Hello Nazila,
To determine the output size for the first fullyConnectedLayer after the lstmLayer, you generally want to consider the complexity of your problem and the amount of data you have. A common approach is to start with a number of neurons that is a multiple of the number of hidden units in the LSTM layer.
Given your setup, you have 15 hidden units in the LSTM layer. A reasonable starting point for the fullyConnectedLayer could be 50 neurons, as you suggested. This is often a good balance between model complexity and computational efficiency.
Here’s how you can modify your code:
numResponses = size(YTrain{1},1);
featureDimension = size(XTrain{1},1);
numHiddenUnits = 15;
layers = [ ...
sequenceInputLayer(featureDimension)
lstmLayer(numHiddenUnits,'OutputMode','sequence')
fullyConnectedLayer(50) %% Adjusted to 50 neurons
dropoutLayer(0.5)
fullyConnectedLayer(numResponses)
regressionLayer];
This configuration should work well for your price prediction task. If you find that the model is underfitting or overfitting, you can experiment with different numbers of neurons in the fullyConnectedLayer to see what works best for your data.
I hope it helps.

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by