Memuat
Memuat
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “LSTM Load Forecasting Class #4: LSTM Model for 24-Hour Ahead Forecasting”.
Other ways we can help with Python.
Learn with a mentor
Scheduled AI & Machine Learning courses with live guidance and a certificate.

Multi-Objective Optimization Course: NSGA-II, MOPSO & Hybrid Algorithms (Python)

ECG Arrhythmia Classification Course with Wavelet & Deep Learning (PyTorch)

ANFIS + PSO/GA Course for Non-Linear Time Series Forecasting (Python)
Have it built for you
No time to learn Python? Our team can do the project for you.

Python Machine Learning — Prediction Models, Customer Segmentation, Fraud Detection & AI Apps

AI Image Creation with Stable Diffusion — Unlimited Custom Visual Production
★ 4.9

AI Image & Video Creation with Leonardo AI — All-in-One Visuals for Business
★ 4.9
Get notified about new Python classes
At most one email a week. Unfollow anytime with one click.
The full narration of this video. The current sentence is highlighted while the video plays; click any sentence to jump there.
This is the final result, an LSTM network that reads the last 168 hours and directly predicts the next 24 hours, with a validation error of about 2.4 percent, much lower than the best baseline. Training takes only a few seconds on the GPU. Let's get started. Hello, welcome to episode four of the electricity load forecasting series using LSTM. LSTM, Long Short-Term Memory, is a recurrent neural network with input, forget, and output gates that decide which information to remember and which to forget. Therefore, LSTM is able to capture both short-term patterns like the previous hour and long-term patterns like last week. Today we build it with PyTorch. Create a file named model_underscore_lstm.py
The LSTM predictor class stacks several LSTM layers one by one with dropout in between. The number of hidden units, the number of layers, and dropout can be adjusted. A linear layer at the end transforms the state of the last hour into 24 numbers. So the model predicts all 24 hours at once, not one by one, so the error does not stack. We use the GPU if available. The training function uses the Adam optimizer and mean squared error loss on the normalized load, with a mini batch of 256.
At the end of each epoch, the validation prediction is converted back to megawatts and its map is calculated. The best model is saved, and if validation does not improve for four consecutive epochs, training is stopped. This is the learning rate scheduler, the preventer of overfitting. The prediction function generates predictions for a set of windows. Create a file named train_underscore_lstm.py and run it.
The initial model uses 64 units and 2 layers, about 54,000 parameters. Each epoch takes less than one second on the GPU. Validation map is about 3.8% in the first epoch, then drops to about 2.4%, already much better than ridge regression. The best model is saved to lstm_underscore_initial.pt. Let's take a look at the graphs.
The left validation curve drops quickly then flattens, indicating where the Arlist Topping is working. The right graph shows the 24-hour forecast for one week of validation, LSTM follows the daily pattern very well, including the drop at the weekend. But are 64 units and 2 layers the best choice? That's the question for the next episode.
Done. We have built a 24-hour forecasting LSTM with PyTorx, trained it with Adam and Arlist Topping, and outperformed all baselines in the validation data. In the next episode, we will optimize the LSTM architecture and hyperparameters using a genetic algorithm. Are you working on a thesis, dissertation, or research in the field of electrical load and time series forecasting? Cerdas Inovasi Digital helps with deep learning implementation, from data load exploration, feature engineering, ARIMA and regression, LSTM with PyTorx, up to hyperparameter optimization with a genetic algorithm, as well as opening deep learning courses with PyTorx. Want to master the entire series, from hourly load data to forecast evaluation? All 6 episodes, complete with PDF step-by-step guides and source code, are available for premium tutorial subscribers. Subscribe starting at Rp69.000 per month, save 28% with the 12-month package, or pay once Rp999.000 for lifetime access. Want just one class? Buy the single class with lifetime access. Subscribe now at the premium page cerdasinovasidigital.com. Contact us via WhatsApp, or visit cerdasinovasidigital.com. Thank you for watching, see you in the next episode. Thank you for watching, see you in the next episode.
Type a question or keyword; we find the part of this episode that explains it and jump the video there.
Notes are saved with the current video time and are only visible to you.
Stuck on a step? Ask here; the instructor and other learners can answer.
No questions yet.

Cerdas Inovasi Digital Team
Software developers, BIM & 3D engineers, and AI practitioners
We build software, BIM models, games and AI automations for clients every day, and turn that hands-on work into step-by-step classes: every step is shown on screen and comes with a PDF guide you can keep.
See our clients →