Skip to content

Repository files navigation

Store Sales Forecasting - Model Comparison Project

This project implements and compares three different approaches for time series forecasting of store sales:

  1. Enhanced TCN (Temporal Convolutional Network with residual blocks)
  2. SARIMA (Seasonal AutoRegressive Integrated Moving Average)
  3. Hybrid (SARIMA + TCN combination)

πŸ“ Project Structure

ML/
β”œβ”€β”€ main.ipynb                          # Enhanced TCN model
β”œβ”€β”€ arima_baseline.ipynb                # SARIMA baseline model
β”œβ”€β”€ hybrid_model.ipynb                  # Hybrid SARIMA+TCN model
β”œβ”€β”€ model_comparison.ipynb              # Comprehensive model comparison
β”œβ”€β”€ data/                               # Training and test data
β”‚   β”œβ”€β”€ train.csv
β”‚   β”œβ”€β”€ test.csv
β”‚   β”œβ”€β”€ oil.csv
β”‚   β”œβ”€β”€ holidays_events.csv
β”‚   └── stores.csv
└── README.md                           # This file

πŸš€ Quick Start

1. Install Dependencies

pip install pandas numpy torch scikit-learn matplotlib pmdarima statsmodels joblib seaborn

2. Run Models (in order)

Option A: Run All Models

# 1. Enhanced TCN (fastest, ~10-15 minutes)
jupyter notebook main.ipynb

# 2. SARIMA Baseline (slow, ~30-60 minutes)
jupyter notebook arima_baseline.ipynb

# 3. Hybrid Model (moderate, ~20-30 minutes)
jupyter notebook hybrid_model.ipynb

# 4. Compare All Models
jupyter notebook model_comparison.ipynb

Option B: Quick Start (Just TCN)

# Run only the TCN model for fastest results
jupyter notebook main.ipynb

πŸ“Š Model Comparison

Model Type Training Time Strengths Weaknesses
TCN Deep Learning ⚑ ~10-15 min Fast, captures complex patterns, handles all series at once Black box, requires GPU
SARIMA Statistical ⏱ ~30-60 min Interpretable, captures linear trends/seasonality Slow with many series, linear only
Hybrid Combined ⚑⏱ ~20-30 min Best of both worlds, interpretable + powerful More complex to maintain

🎯 Recommended Workflow

For Best Predictions:

  1. Run all three models
  2. Use the Weighted Ensemble from model_comparison.ipynb
  3. Weights: 30% TCN, 20% SARIMA, 50% Hybrid

For Production Deployment:

  1. Use Enhanced TCN from main.ipynb
  2. Fast inference, easy to update with new data
  3. Scales well with more data

For Stakeholder Presentations:

  1. Use SARIMA from arima_baseline.ipynb
  2. Interpretable coefficients
  3. Clear trend/seasonality decomposition

πŸ“ˆ Key Features

Enhanced TCN (main.ipynb)

  • βœ… Residual blocks with skip connections
  • βœ… Batch normalization & dropout
  • βœ… Learning rate scheduling & early stopping
  • βœ… Gradient clipping
  • βœ… 180-day lookback (6 months for seasonality)
  • βœ… Integrated oil prices & holidays

SARIMA Baseline (arima_baseline.ipynb)

  • βœ… Automatic parameter selection (auto_arima)
  • βœ… Parallel processing for 1,782 time series
  • βœ… Weekly seasonality (m=7)
  • βœ… Robust error handling with fallback to mean
  • βœ… Validation metrics & visualizations

Hybrid Model (hybrid_model.ipynb)

  • βœ… Stage 1: SARIMA captures trend/seasonality
  • βœ… Stage 2: TCN models residuals (non-linear patterns)
  • βœ… Final prediction = SARIMA + TCN_residuals
  • βœ… Best accuracy with interpretability

πŸ“‹ Output Files

Submissions

  • submission.csv - TCN predictions
  • submission_sarima.csv - SARIMA predictions
  • submission_hybrid.csv - Hybrid predictions
  • submission_ensemble_simple.csv - Simple average ensemble
  • submission_ensemble_weighted.csv - ⭐ Recommended weighted ensemble

Model Files

  • best_model.pth - Best TCN model (validation)
  • final_model.pth - Final TCN model (full data)
  • sarima_models.pkl - Trained SARIMA models
  • hybrid_sarima_models.pkl - Hybrid SARIMA component
  • hybrid_tcn_final.pth - Hybrid TCN component

Visualizations

  • predictions_visualization.png - TCN sample predictions
  • sarima_validation_predictions.png - SARIMA validation
  • hybrid_decomposition.png - SARIMA vs residuals
  • hybrid_predictions_visualization.png - Hybrid predictions
  • model_comparison_*.png - Various comparison plots

πŸ”§ Customization

Adjust TCN Parameters (main.ipynb)

INPUT_LENGTH = 180        # Lookback window (days)
OUTPUT_LENGTH = 16        # Forecast horizon (days)
BATCH_SIZE = 32          # Batch size for training
hidden_channels = 128    # Model capacity
num_blocks = 4           # Number of residual blocks
dropout = 0.2            # Dropout rate

Adjust SARIMA Parameters (arima_baseline.ipynb)

max_p = 3               # Max AR order
max_q = 3               # Max MA order
max_P = 2               # Max seasonal AR order
max_Q = 2               # Max seasonal MA order
m = 7                   # Seasonal period (weekly)

πŸ“Š Performance Metrics

The model_comparison.ipynb notebook provides:

  • βœ… RMSE, MAE, MAPE on validation set
  • βœ… Prediction distribution analysis
  • βœ… Time series visualizations
  • βœ… Correlation between models
  • βœ… Statistical comparison tables

πŸŽ“ Key Insights

Why TCN over LSTM/GRU?

  • βœ… Parallel processing (faster training)
  • βœ… Longer effective history (dilated convolutions)
  • βœ… More stable gradients
  • βœ… Better for very long sequences

Why SARIMA Still Matters?

  • βœ… Interpretable for business stakeholders
  • βœ… Works with less data
  • βœ… Captures explicit seasonality
  • βœ… Good baseline for comparison

Why Hybrid Approach?

  • βœ… SARIMA handles predictable patterns
  • βœ… TCN handles complex residuals
  • βœ… Combines strengths of both
  • βœ… Often outperforms either alone

πŸ› Troubleshooting

SARIMA Takes Too Long

  • Reduce the number of series (sample first)
  • Simplify parameter space in auto_arima
  • Use more CPU cores (n_jobs=-1)

Out of Memory (TCN)

  • Reduce BATCH_SIZE
  • Reduce INPUT_LENGTH
  • Reduce hidden_channels
  • Use CPU instead of GPU if available

Poor Predictions

  • Check data quality and missing values
  • Increase INPUT_LENGTH for more context
  • Try different train/val split ratios
  • Experiment with different model architectures

πŸ“š References

πŸ“ž Support

For questions or issues:

  1. Check the troubleshooting section
  2. Review the notebook comments
  3. Examine the visualization outputs
  4. Compare with baseline metrics

πŸŽ‰ Results

After running all notebooks, you'll have:

  • βœ… 5 different submission files
  • βœ… Multiple trained models
  • βœ… Comprehensive visualizations
  • βœ… Performance metrics comparison
  • βœ… Clear recommendation for production

Recommended submission: submission_ensemble_weighted.csv


Happy Forecasting! πŸ“ˆπŸš€

About

No description, website, or topics provided.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages