Skip to content

net421/demand-forecasting

Repository files navigation

🔮 Demand Forecasting — Supply Chain ML

Supply Chain Analytics Project | Python · scikit-learn · pandas · matplotlib
Part of a logistics optimization portfolio by Emmanuel Beristain Guzmán


Overview

Predicts monthly product demand using three progressively advanced models — from a simple moving average baseline to a machine learning ensemble. Built to demonstrate applied knowledge of forecasting methodology, feature engineering, and model evaluation in a supply chain context.

This type of analysis directly supports inventory planning, procurement scheduling, and MRP configuration in systems like SAP.


Models Compared

Model Type Description
Moving Average Statistical baseline Rolling mean of last 3 months
Linear Regression ML — interpretable Trend + seasonality features
Random Forest ML — ensemble 200 trees, lag + calendar features

Features Engineered

Feature Description
t Time index (captures trend)
sin_month, cos_month Cyclical encoding of month (captures seasonality)
is_q4 Q4 flag — Oct/Nov/Dec peak season
lag_1, lag_2 Demand from 1 and 2 months ago
lag_12 Demand from same month last year
rolling_3_mean 3-month rolling average
rolling_6_mean 6-month rolling average
rolling_3_std 3-month rolling standard deviation

Metrics Used

Metric Meaning
MAE Mean Absolute Error — average units off
RMSE Root Mean Squared Error — penalizes large errors
MAPE Mean Absolute % Error — model accuracy in %
How much variance is explained by the model

Sample Output

══════════════════════════════════════════════════════════
  DEMAND FORECASTING — MODEL COMPARISON REPORT
══════════════════════════════════════════════════════════
  Model                     MAE    RMSE     MAPE      R²
────────────────────────────────────────────────────────
  Moving Average           42.3    51.8    9.87%   0.712
  Linear Regression        28.1    34.5    6.43%   0.881
  Random Forest            18.7    23.2    4.21%   0.947
────────────────────────────────────────────────────────

  Best model: Random Forest (MAPE = 4.21%)

  Top 5 features (Random Forest):
  lag_1                ████████████████ 0.412
  rolling_3_mean       ████████████     0.298
  lag_12               ████████         0.187
  t                    ████             0.063
  sin_month            ██               0.024
══════════════════════════════════════════════════════════

Charts Generated

Full forecast chart (4 panels):

  • Historical demand + all model predictions
  • Zoom into test period (last 6 months)
  • MAPE comparison bar chart
  • Random Forest feature importance

Forecast chart


Project Structure

demand-forecasting/
│
├── demand_forecasting.py      # Main script — data, models, charts
├── requirements.txt
├── README.md
│
└── data/                      # Auto-generated on first run
    ├── forecast_chart.png     # 4-panel visualization
    ├── forecast_predictions.csv
    └── model_metrics.csv

Getting Started

1. Clone the repo

git clone https://github.com/net421/demand-forecasting.git
cd demand-forecasting

2. Install dependencies

pip install -r requirements.txt

3. Run the forecaster

python demand_forecasting.py

How It Works

Raw demand data (36 months)
        ↓
Feature engineering (lag, rolling, calendar)
        ↓
Train / test split (last 6 months = test)
        ↓
Train 3 models simultaneously
        ↓
Evaluate: MAE · RMSE · MAPE · R²
        ↓
Export predictions + chart

Business Application

This forecasting logic maps directly to supply chain planning tools:

This script SAP / ERP equivalent
Moving average Simple forecast in SAP APO / IBP
Trend + seasonality Holt-Winters in SAP Demand Planning
Random Forest Advanced ML in SAP IBP for demand
Feature: lag_12 Seasonal reference in MRP planning
Feature: is_q4 Promotional planning / peak season buffer
MAPE metric Forecast accuracy KPI in S&OP reviews

Accurate demand forecasting reduces inventory costs, prevents stockouts, and improves supplier scheduling — all core outcomes measured in SAP MM/PP implementations.


Tech Stack

Tool Use
Python 3.10+ Core logic
pandas Data manipulation
numpy Numerical computation
scikit-learn ML models (LinearRegression, RandomForest)
matplotlib Multi-panel visualization

Skills Demonstrated

  • Time series feature engineering (lag, rolling, cyclical encoding)
  • Supervised ML for regression (Linear, Random Forest)
  • Model evaluation and comparison methodology
  • Demand planning concepts (MAPE, seasonality, trend)
  • Supply chain forecasting aligned with S&OP processes
  • Python scripting for logistics automation

About

Emmanuel Beristain Guzmán
Logistics Engineer | Supply Chain Analytics | SAP Functional Trainee
📍 México (Remote) · 📧 emmanuel.beristain.guzman@gmail.com
🔗 github.com/net421


Part of a series of supply chain analytics projects. See also: EOQ/ROP inventory simulator, logistics dashboard, and VRP route optimization.

About

Demand forecasting models for supply chain and inventory planning

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages