This project implements and compares three different approaches for time series forecasting of store sales:
- Enhanced TCN (Temporal Convolutional Network with residual blocks)
- SARIMA (Seasonal AutoRegressive Integrated Moving Average)
- Hybrid (SARIMA + TCN combination)
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
pip install pandas numpy torch scikit-learn matplotlib pmdarima statsmodels joblib seaborn# 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# Run only the TCN model for fastest results
jupyter notebook main.ipynb| 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 |
- Run all three models
- Use the Weighted Ensemble from
model_comparison.ipynb - Weights: 30% TCN, 20% SARIMA, 50% Hybrid
- Use Enhanced TCN from
main.ipynb - Fast inference, easy to update with new data
- Scales well with more data
- Use SARIMA from
arima_baseline.ipynb - Interpretable coefficients
- Clear trend/seasonality decomposition
- β 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
- β 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
- β Stage 1: SARIMA captures trend/seasonality
- β Stage 2: TCN models residuals (non-linear patterns)
- β Final prediction = SARIMA + TCN_residuals
- β Best accuracy with interpretability
submission.csv- TCN predictionssubmission_sarima.csv- SARIMA predictionssubmission_hybrid.csv- Hybrid predictionssubmission_ensemble_simple.csv- Simple average ensemblesubmission_ensemble_weighted.csv- β Recommended weighted ensemble
best_model.pth- Best TCN model (validation)final_model.pth- Final TCN model (full data)sarima_models.pkl- Trained SARIMA modelshybrid_sarima_models.pkl- Hybrid SARIMA componenthybrid_tcn_final.pth- Hybrid TCN component
predictions_visualization.png- TCN sample predictionssarima_validation_predictions.png- SARIMA validationhybrid_decomposition.png- SARIMA vs residualshybrid_predictions_visualization.png- Hybrid predictionsmodel_comparison_*.png- Various comparison plots
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 ratemax_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)The model_comparison.ipynb notebook provides:
- β RMSE, MAE, MAPE on validation set
- β Prediction distribution analysis
- β Time series visualizations
- β Correlation between models
- β Statistical comparison tables
- β Parallel processing (faster training)
- β Longer effective history (dilated convolutions)
- β More stable gradients
- β Better for very long sequences
- β Interpretable for business stakeholders
- β Works with less data
- β Captures explicit seasonality
- β Good baseline for comparison
- β SARIMA handles predictable patterns
- β TCN handles complex residuals
- β Combines strengths of both
- β Often outperforms either alone
- Reduce the number of series (sample first)
- Simplify parameter space in
auto_arima - Use more CPU cores (
n_jobs=-1)
- Reduce
BATCH_SIZE - Reduce
INPUT_LENGTH - Reduce
hidden_channels - Use CPU instead of GPU if available
- Check data quality and missing values
- Increase
INPUT_LENGTHfor more context - Try different train/val split ratios
- Experiment with different model architectures
- TCN Paper: An Empirical Evaluation of Generic Convolutional and Recurrent Networks for Sequence Modeling
- SARIMA: Box, Jenkins, Reinsel - Time Series Analysis
- Hybrid Approaches: Zhang (2003) - Time series forecasting using a hybrid ARIMA and neural network model
For questions or issues:
- Check the troubleshooting section
- Review the notebook comments
- Examine the visualization outputs
- Compare with baseline metrics
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! ππ