This project realises a time sequence prediction framework that can be reproduced, expandible, and directly used for scientific research or engineering experiments, combined with:
- ✅ LSTM neural network (PyTorch)
- ✅ Bayesian optimisation (Optuna) (Optuna)
- ✅ three Multi-step prediction strategy:
- Recursive (recursive prediction)
- Multi-output (multi-output prediction)
- Direct (direct prediction)
- ✅ Automatically download and load the public data set
- ✅ Notebook Visualisation and Experimental Analysis
Time-series-lstm-optuna/
├──data/
│└── README.md
├── models/
│ └── lstm_model.py
├──utils/
│ └── data_utils.py
├── notebooks/
│ └── 01_explore_and_train.ipynb
├── train_lstm_optuna.py
├──train_nooptuna.py
├── requirements.txt
├── README.md
└──LICENSE
- Prepare project documents
Create a directory locally and save the complete source code provided above to the corresponding file (it is recommended to copy and paste the contents of each file directly).
- Create a virtual environment and install dependencies
Create a virtual environment Python -m venv .venv Activate the virtual environment Source .venv/bin/activate #Mac/Linux.venv\Scripts\activate#Windows (PowerShell) Installation Dependency Pip install -r requirements.txt - Running hyperparameter optimisation example (recommended)
Use Optuna to run a small-scale training task to confirm that everything is normal:
Python train_lstm_optuna.py --csv data/daily-min-temperatures.csv --trials 12 --epochs 8 --horizon 1 4 --strategy multioutput --out-dir outputs - Run a lightweight quick start
If you don't want to use Optuna, you can run a lighter version:
Python train_nooptuna.py After the run is completed, three previews will be generated under the outputs/ catalogue:
-
forecast_preview_multioutput.png
-
forecast_preview_recursive.png
-
forecast_preview_direct.png
- Push the repository to GitHub
Replace with your actual warehouse address:
Git init Git add. Git commit -m "Add LSTM + Optuna time series repo (multi-step strategies)" Git remote add origin <your-repo-url> Git branch-M main Git push -u origin main Or use GitHub CLI (gh) to automatically create and push:
Gh repo create <your-username>/<repo-name> --public --source=. --remote=origin --push Description and Reference (Important)
-
Data source: The sample data adopts Daily Minimum Temperatures in Melbourne (1981–1990). The script will automatically process the download logic.
-
Multi-step prediction strategy description:
-
Recursive: Train the 1-step model and use "rolling prediction" to generate multiple steps. Advantages: few parameters; Disadvantages: errors will accumulate with the number of steps.
-
Multi-output: The model directly outputs the entire Horizon length. Advantages: no accumulation of errors; disadvantages: more parameters and training data are required.
-
Direct: Train an independent model for each Horizon Step. Advantages: highly targeted, usually the most stable; Disadvantages: high computing cost (multiple models need to be trained).
Tip: The script of this warehouse supports the above three strategies at the same time. In direct mode, the system will train an independent model for each step after finding the best hyperparatra, which is suitable for scenarios with high requirements for long-term prediction stability.