📈 Machine Learning

Intelligent Demand Forecasting System

An ensemble forecasting engine with 15+ algorithms that automatically selects the best model based on demand pattern classification using ADI/CV² analysis.

Role Data Engineer
Industry Retail Supply Chain
Duration 6 months
SKUs 10,000+
15+
Algorithms in Ensemble
4
Pattern Categories
85%
Forecast Accuracy
30%
Stockout Reduction

The Challenge

Supply chain forecasting is notoriously difficult because not all products behave the same way. A best-seller with consistent daily sales needs a different forecasting approach than a slow-moving spare part ordered once a month.

The existing system used a one-size-fits-all approach—applying the same simple moving average to all 10,000+ SKUs. This led to:

The Solution

I built an intelligent forecasting system that classifies each SKU's demand pattern and automatically selects the most appropriate algorithm from an ensemble of 15+ models.

📊
Historical Data
🔍
Pattern Analysis
🎯
ADI/CV² Classification
🤖
Model Selection
📈
Forecast Output

Pattern Classification (ADI/CV²)

The system uses two key metrics to classify demand patterns:

📈
Smooth
ADI < 1.32 AND CV² < 0.49

Regular, predictable demand. Best for time series models.

→ ARIMA, Prophet, Holt-Winters
📊
Erratic
ADI < 1.32 AND CV² ≥ 0.49

Frequent but variable demand. Needs robust methods.

→ Random Forest, XGBoost, Croston
Intermittent
ADI ≥ 1.32 AND CV² < 0.49

Infrequent but consistent quantities when ordered.

→ Croston, SBA, TSB
🎲
Lumpy
ADI ≥ 1.32 AND CV² ≥ 0.49

Rare and unpredictable. Hardest to forecast.

→ TSB, Bootstrap, Safety Stock Models

Algorithm Ensemble

The system includes 15+ forecasting algorithms, each optimized for different demand characteristics:

ARIMA

Auto-regressive integrated moving average for stationary series

Time Series

Prophet

Facebook's model for seasonality and holiday effects

Seasonality

Holt-Winters

Triple exponential smoothing for trends

Trending

XGBoost

Gradient boosting with feature engineering

ML

Random Forest

Ensemble of decision trees for robustness

ML

Croston

Specialized for intermittent demand

Intermittent

SBA

Syntetos-Boylan Approximation

Intermittent

TSB

Teunter-Syntetos-Babai for lumpy demand

Lumpy

Simple Exponential

Baseline model for stable demand

Baseline

+ Moving Averages, Linear Regression, LSTM, Theta Method, Naive Methods, and more...

Implementation

The pattern classifier uses a clean, configurable design:

pattern_classifier.py
class DemandPatternClassifier:
    """Classify SKU demand patterns using ADI/CV² analysis."""
    
    def __init__(self, adi_threshold=1.32, cv2_threshold=0.49):
        self.adi_threshold = adi_threshold
        self.cv2_threshold = cv2_threshold
        
    def classify(self, demand_series: pd.Series) -> DemandPattern:
        # Calculate Average Demand Interval
        non_zero_periods = (demand_series > 0).sum()
        adi = len(demand_series) / non_zero_periods if non_zero_periods > 0 else float('inf')
        
        # Calculate CV² (squared coefficient of variation)
        non_zero_demand = demand_series[demand_series > 0]
        cv2 = (non_zero_demand.std() / non_zero_demand.mean()) ** 2
        
        # Classify based on thresholds
        if adi < self.adi_threshold and cv2 < self.cv2_threshold:
            return DemandPattern.SMOOTH
        elif adi < self.adi_threshold and cv2 >= self.cv2_threshold:
            return DemandPattern.ERRATIC
        elif adi >= self.adi_threshold and cv2 < self.cv2_threshold:
            return DemandPattern.INTERMITTENT
        else:
            return DemandPattern.LUMPY

Tech Stack

Python Pandas Scikit-learn Statsmodels Prophet XGBoost Polars DuckDB

Key Learnings

No Silver Bullet

Different demand patterns need different algorithms. The classifier approach improved accuracy by 25% over one-size-fits-all.

Intermittent is Hard

40% of SKUs had intermittent/lumpy demand. Croston and TSB significantly outperformed traditional methods here.

Feature Engineering Matters

Adding promotional calendars, seasonality flags, and lead time features boosted ML model accuracy by 15%.

Explainability Wins Trust

Showing planners WHY a forecast was generated (pattern type, algorithm used) increased adoption significantly.

Interested in the Details?

Let's discuss how intelligent forecasting can transform your supply chain operations.