Using LSTM to do time series data prediction get wrong output

username: Givan
cooked: <p>Hello, when I do the time series data prediction using LSTM model, the outcome is pretty confusing for me. I want predict the one month’ electricity using the sequence of last year.<br>
When epoch = 100, one of predictions is shown:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/a/6a503ef8a7e6178d2d9eb87170b61fc2de2e33b8.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/6a503ef8a7e6178d2d9eb87170b61fc2de2e33b8" title="1"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/a/6a503ef8a7e6178d2d9eb87170b61fc2de2e33b8_2_690x337.jpeg" alt="1" data-base62-sha1="fauxmq1hakmQ7KxojcdCSiR7FIk" width="690" height="337" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/a/6a503ef8a7e6178d2d9eb87170b61fc2de2e33b8_2_690x337.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/6/a/6a503ef8a7e6178d2d9eb87170b61fc2de2e33b8_2_1035x505.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/6/a/6a503ef8a7e6178d2d9eb87170b61fc2de2e33b8_2_1380x674.jpeg 2x" data-dominant-color="F6F4F0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">1</span><span class="informations">1509×738 111 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>change the number of epoch is the same.</p>
<p>why the pattern of every day’s prediction is the same. Is there anything wrong?</p>
<p>Thanks!!!</p>

username: ptrblck
cooked: <p>It seems your model is not learning the right pattern.<br>
I would recommend to select a small subset of the data (e.g. just 10 samples) and try to overfit this dataset.<br>
Once your model successfully predicts the target, you could then scale up the use case.<br>
If your model is unable to do so, there might be a bug in the code or the model architecture is not suitable for this task.</p>

username: googlebot
cooked: <p>If you view your output as global_bias + phase_adjustment(t) + timeseries_specific_adjustment(t,x), conclusion would be that the last component was not learned. If you start your rnn with zero context, this can mean that your timeseries have no distinguishing features when fed step-by-step, to have non-zero timeseries specific bias (encoded in hidden state). In other cases such features may be missed (try GRU and slower training).</p>

username: Givan
cooked: <p>Thank You, Alex. If the timeseries_specific_adjustment was not learned, is there any techniques to improve it? I have tried slower training as you said.</p>

username: Givan
cooked: <p>Thank you, ptrblck. I tried 30 samples, the prediction is almost the same. Although it changed a little, the pattern of each day is the same. That is the result:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/7/67cddae0c51ba54a94dda7d7d1c506559bbbd4cc.png" data-download-href="https://discuss.pytorch.org/uploads/default/67cddae0c51ba54a94dda7d7d1c506559bbbd4cc" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/7/67cddae0c51ba54a94dda7d7d1c506559bbbd4cc_2_690x341.png" alt="image" data-base62-sha1="eOidKnzgj4f2J8RcBqiDgRha48I" width="690" height="341" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/7/67cddae0c51ba54a94dda7d7d1c506559bbbd4cc_2_690x341.png, https://discuss.pytorch.org/uploads/default/optimized/3X/6/7/67cddae0c51ba54a94dda7d7d1c506559bbbd4cc_2_1035x511.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/6/7/67cddae0c51ba54a94dda7d7d1c506559bbbd4cc.png 2x" data-dominant-color="F2EFEB"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1162×575 167 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: googlebot
cooked: <aside class="quote no-group" data-username="Givan" data-post="4" data-topic="80461">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/g/3ab097/48.png" class="avatar"> Givan:</div>
<blockquote>
<p>If the timeseries_specific_adjustment was not learned, is there any techniques to improve it</p>
</blockquote>
</aside>
<p>What inputs is your rnn receiving?</p>

username: Givan
cooked: <p>The temperature of last year. seq_len = 24 * 365. The output is the electricity of next month, 24 * 30.</p>

username: googlebot
cooked: <p>Well, you should at least feed it things like month, day of week, hour of day (one-hot encoding is the simplest way). But I don’t think you can do much better than your second plot.</p>
<p>In general, that’s not a good task for neural networks. Usual forecasting methods decompose seasonal data (nb: explicitly defined) and use relatively simple formulas to forecast the remainder stepwise. And there is not much else you can do, that would generalize to unseen data.</p>
<p>Use of RNNs may be justified when many “features” with complex interactions are present, but in your case deseasoned fluctuations are likely “unexplainable”.</p>
<p>Maybe you should try something like <a href="https://research.fb.com/prophet-forecasting-at-scale/" rel="nofollow noopener">Prophet</a>. For more basic ideas, you may check <a href="https://otexts.com/fpp2/" rel="nofollow noopener">online book</a></p>