MATLAB Answers

How to use LSTM and CNN to handle a regression problem?

조회 수: 102(최근 30일)
Hui Li
Hui Li 2020년 7월 14일
답변: H Sanchez 2021년 4월 30일
Hi, everyone!
I am working on a solar power prediction problem. The inputs of the network are some kinds of meteological data, and the outputs are multiple time-series solar power curves. I want to build a neural network combining LSTM and CNN to realize this function. I build a network without error like this:
layers1 = [...
sequenceInputLayer([25 168 1],'Name','input') % 25 is the number of feature dimension of meteological data, and 168 is the length of time series
lgraph = layerGraph(layers1);
lgraph = connectLayers(lgraph,'fold/miniBatchSize','unfold/miniBatchSize');
However, the flattenLayer destory the time series, and the training cannot be finished.
Therefore, is there any solution about this problem? Or is there any other correct network can realize the same function?
Thanks in advance for your time and kindly help!


Abolfazl Nejatian
Abolfazl Nejatian 2020년 12월 10일
Dear Gupta,
i have written a prediction code that uses CNNs and LSTM to forecast future values.
please visit my Mathworks page,

H Sanchez
H Sanchez 2021년 4월 30일
To Whoever is looking for a CNN-RNN
I have created a simple template for hybrids cnn-rnn for time series forecasting.

Raunak Gupta
Raunak Gupta 2020년 7월 19일
I am unable to understand what exactly you are doing with input and output of the network, but I think its related to either sequence to sequence regression or time series forecasting. You may follow below mentioned examples for both cases and see if it matches with your application.
  댓글 수: 2
Raunak Gupta
Raunak Gupta 2020년 7월 19일
I don't see any lstmLayer inside the Layer Graph, maybe you can add it. Also can you share a sample input and output with the code you trying with. It will help me recreating the problem and also checking if flattenLayer is indeed required or not.

댓글을 달려면 로그인하십시오.




Community Treasure Hunt

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

Start Hunting!

Translated by