Aditya Sridhar

Model · Oct 2026 · runs in your browser

LSTM forecaster

Every model before this one looks at a single image. Demand is a sequence: what happens at 18:00 depends on the afternoon before it, the weather, the day of the week and where the sun is. An LSTM reads the last 24 hours one five-minute step at a time and forecasts the next hour, the problem behind my forecasting paper, here on a public dataset.

Test MAPE, 2024, 1 h ahead
1.06%
Same time yesterday
6.30%
Parameters
204,300
Training time
3.0 min, GPU

Try it

  • Actual
  • LSTM, an hour ahead
  • Same time yesterday
  • Sun elevation (an input)

Loading…

Runs in your browser.

The shaded curve is the sun's elevation over Delhi, computed from the date and time. It is one of the inputs: rooftop solar output is not in the data, but the sun's position is a proxy for when it lowers the demand the grid sees.

Results

MetricValueSource
LSTM, mean absolute percentage error over the 12 steps of 2,766 hourly forecasts in 20241.06%training/lstm_load/log.csv, epoch 12
LSTM, mean absolute error50 MWtraining/lstm_load/log.csv, epoch 12
Persistence: the last value, held for the hour2.70%public/models/lstm-load/meta.json
Same time yesterday6.30%public/models/lstm-load/meta.json
LSTM by horizon: 5 minutes ahead → 60 minutes ahead0.49% → 1.59%public/models/lstm-load/meta.json

The test year was never used to choose anything: the schedule is fixed and the last epoch is reported. The error is computed on the same forecast origins for the model and both baselines.

Training run

Test MAPE per epoch, %LSTM, 2024
1.001.502.00135791112epoch 1 · LSTM, 2024 2.18epoch 2 · LSTM, 2024 1.59epoch 3 · LSTM, 2024 1.35epoch 4 · LSTM, 2024 1.21epoch 5 · LSTM, 2024 1.22epoch 6 · LSTM, 2024 1.20epoch 7 · LSTM, 2024 1.14epoch 8 · LSTM, 2024 1.14epoch 9 · LSTM, 2024 1.08epoch 10 · LSTM, 2024 1.08epoch 11 · LSTM, 2024 1.06epoch 12 · LSTM, 2024 1.06

Tracked for the chart only; nothing was selected on it.

How it works

Inputs. For each of the last 288 five-minute steps: load, temperature, relative humidity, time of day and day of week (each as a sine and cosine, so 23:55 sits next to 00:00), and the sine of the sun's elevation at Delhi from standard declination and equation-of-time formulas. The model normalises its inputs itself, so the browser feeds raw values.

Network. A 2-layer LSTM with 128 units reads the sequence; its last state goes through one linear layer to 12 outputs, predicted as changes from the last observed load.

Data handling. The data is put on a full five-minute grid. Gaps of up to an hour are interpolated; any window that touches a longer gap is skipped. Some days in the file carry another day's load (a March day with a summer profile), which shows up as an impossible jump at midnight, so any change between neighbouring readings above 8% (scaled by the square root of the steps between them) also breaks the series. Training uses 2021 to 2023 (58,228 windows, one every 15 minutes), testing all of 2024 up to the end of the data.

Training. AdamW, one-cycle learning rate peaking at 0.002, batch 512, 12 epochs, mean squared error on normalised load.

Reproduce

Hardware
NVIDIA GeForce RTX 3050 Laptop GPU, PyTorch 2.6.0+cu124
Commit
c009e6d
Data
Delhi 5-Minute Electricity Demand for Forecasting, 2021-01-01 to 2024-12-12, CC BY 4.0. Load is labelled kW in the file; the values are MW.

Environment

pip install torch numpy onnx onnxruntime kaggle

Data

kaggle datasets download yug201/delhi-5-minute-electricity-demand-for-forecasting -p training/data/delhi --unzip

Train, export, check

python training/lstm_load/train.py

Data: Delhi 5-Minute Electricity Demand for Forecasting by yug201 on Kaggle, licensed CC BY 4.0.