Skip to content

A hands-on project for forecasting time-series with PyTorch LSTMs. It creates realistic daily data (trend, seasonality, events, noise), prepares it with sliding windows, and trains an LSTM to make multi-step predictions. The project tracks errors with RMSE, MAE, MAPE and shows clear plots of training progress and forecast results.

License

Notifications You must be signed in to change notification settings

AmirhosseinHonardoust/LSTM-Time-Series-Forecasting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LSTM Time-Series Forecasting

A hands-on project for forecasting time-series with PyTorch LSTMs. It creates realistic daily data (trend, seasonality, events, noise), prepares it with sliding windows, and trains an LSTM to make multi-step predictions. The project tracks errors with RMSE, MAE, MAPE and shows clear plots of training progress and forecast results.


Features

  • Synthetic daily series generation (configurable length & seed)
  • Sliding-window dataset preparation for supervised learning
  • LSTM model with dropout, Adam optimizer, early stopping
  • Multi-step forecasting (direct & recursive)
  • Metrics: RMSE, MAE, MAPE
  • Visualizations: training curves & forecast plots
  • Saved artifacts: best_lstm.pt, scaler.pkl, metrics.json

Results

  • RMSE: 22.25
  • MAE: 16.09
  • MAPE: 7.64%

Forecast vs Actual

forecast_plot

Training & Validation Loss

training_curves

Project Structure

lstm-time-series-forecasting/
├─ README.md
├─ LICENSE
├─ requirements.txt
├─ data/
│  └─ generate_series.py
├─ src/
│  ├─ train_lstm.py
│  ├─ evaluate.py
│  └─ utils.py
└─ outputs/
   ├─ metrics.json
   ├─ forecast_plot.png
   ├─ training_curves.png
   ├─ best_lstm.pt
   ├─ scaler.pkl
   └─ (auto-created figures & reports)

Setup

python -m venv .venv
# Windows:
.venv\Scripts\activate
# macOS/Linux:
source .venv/bin/activate
pip install -r requirements.txt

Generate Data

python data/generate_series.py --start 2020-01-01 --end 2025-12-31 --seed 42 --out data/daily_series.csv

Train Model

python src/train_lstm.py --input data/daily_series.csv --horizon 30 --lookback 60 --epochs 30 --batch-size 64 --outdir outputs --seed 42

Evaluate

python src/evaluate.py --input data/daily_series.csv --model outputs/best_lstm.pt --lookback 60 --horizon 30 --outdir outputs

Outputs

  • outputs/metrics.json – RMSE, MAE, MAPE
  • outputs/training_curves.png – training & validation curves
  • outputs/forecast_plot.png – forecast visualization
  • outputs/best_lstm.pt – trained PyTorch model
  • outputs/scaler.pkl – fitted scaler

About

A hands-on project for forecasting time-series with PyTorch LSTMs. It creates realistic daily data (trend, seasonality, events, noise), prepares it with sliding windows, and trains an LSTM to make multi-step predictions. The project tracks errors with RMSE, MAE, MAPE and shows clear plots of training progress and forecast results.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages