LSTM Seasonal Regression / Forecasting #
This is the runnable supervised sequence example: an LSTM trains on a real-valued forecasting task and works with the same CPU/CUDA runtime flags as the other model commands.
The default data path uses the UCI Individual Household Electric Power Consumption dataset: minute-level power readings from one household over almost four years. The preparation script turns that into hourly one-step forecasting windows:
past 24 hours -> next 24 shifted-by-one-hour targets
Prepare the real data once:
python3 scripts/datasets/download_example_data.py --household-power --household-power-windows 512
Recommended runs:
- use
--steps 1to check that the runtime, data loader, and CUDA path agree on shapes; - use
--steps 200 --windows 96for a short training run with before/after forecast reports; - change
--report-offsetto evaluate a different part of the power curve; - lower
--lrif the reported forecast error increases.
lake exe -K cuda=true torchlean lstm_regression --cuda --steps 1 --windows 1
lake exe -K cuda=true torchlean lstm_regression --cuda --steps 200 --windows 96
Dataset citation: Hebrail and Berard, "Individual Household Electric Power Consumption", UCI Machine
Learning Repository, DOI 10.24432/C58K54, CC BY 4.0.
Runner subcommand: lake exe torchlean lstm_regression ....
Instances For
Default JSON path for the before/after loss.
Pass --log PATH to write somewhere else, or --log disabled when you only want terminal output.
Instances For
Default root for downloaded real datasets. Override with --data-dir.
Instances For
Prepared household-power windows contain one day of hourly samples.
Instances For
Short prefix used by the runnable recurrent example.
Instances For
One scalar feature. If you add calendar/weather features, increase this and update scalarRow.
Instances For
Shared recurrent-model configuration.
The model constructor, input shape, and output shape all read from seqLen, inputSize, and
hiddenSize. If a shape error appears, start here.
Instances For
Target/prediction shape: one next-step scalar at each of seqLen timesteps.
Instances For
Raw input shape stored by the prepared household-power .npy files.
Instances For
Raw target shape stored by the prepared household-power .npy files.
Instances For
The actual forecaster.
nn.models.lstmWithLinearHead cfg expands to:
nn.LSTM seqLen inputSize hiddenSize
followed by a time-distributed nn.Linear hiddenSize inputSize.
So every timestep emits a scalar forecast. We are not using only the final hidden state here; the loss checks the whole output sequence.
Instances For
Data source tags for terminal logs and JSON metadata.
Instances For
Validate the prepared input file and return its available window count.
Instances For
Load the Float version once for reporting probes and short training.
Instances For
Keep the first seqLen rows of a prepared rawSeqLen × 1 tensor.
Instances For
Convert one real 24-hour prepared window into the tiny recurrent training sample.
Instances For
Read t[row,0] from a seqLen × 1 forecast tensor.
The row is clamped so the reporting loop remains valid if seqLen is changed without also updating
the number of displayed rows.
Instances For
Render the first few target values for one forecast window.
Instances For
Public trainer probe for a deterministic forecast window.