Machine Learning ➔ Forecasting Engine

Inventory Capital Optimizer

> Protected $2.44B in revenue from stockout risks and released $10.43M in trapped capital by replacing static Min/Max reorder rules with a dynamic, ML-driven optimization engine.

Revenue Leakage Protected

$2.44B

from Stockout Risks

Trapped Capital Released

$10.43M

from Intelligent Buffering

Core Algorithm

XGBoost / LightGBM

14,000+ SKU-level Models

Actionable Metric

SPEC Scorer

Financial Cost > Stats Error

Interactive Dashboard

Custom Scoring Logic

Standard metrics like RMSE are symmetric and fail to account for the asymmetric costs of inventory management. Our SPEC (Stock-keeping-oriented Prediction Error Costs) scorer penalizes stockouts more heavily than overstocks to prioritize revenue protection.

pipeline.py
# Custom Metric: SPEC (Stock-keeping-oriented Prediction Error Costs)
def calculate_spec_grouped(y_true, y_pred, product_ids):
    """
    Calculates cumulative cost of errors per SKU to prevent cross-product pollution.
    Penalizes stockouts (0.75) vs overstocks (0.25).
    """
    eval_df = pd.DataFrame({'PID': product_ids, 'Actual': y_true, 'Pred': y_pred})
    sku_costs = []

    for _, group in eval_df.groupby('PID'):
        act, pre = group['Actual'].values, group['Pred'].values
        n = len(act)
        if n == 0: continue
        
        cum_act, cum_pre = np.cumsum(act), np.cumsum(pre)
        cost = 0.0
        
        for t in range(n):
            # Calculate unfulfilled demand and excess inventory
            unfulfilled = np.maximum(0, cum_act[:t+1] - cum_pre[t])
            excess = np.maximum(0, cum_pre[:t+1] - cum_act[t])
            
            # Weighted penalty: Stockout risk is 3x more costly than trapped capital
            penalties = np.maximum(unfulfilled * 0.75, excess * 0.25)
            cost += np.sum(penalties * (t - np.arange(t+1) + 1))
            
        sku_costs.append(cost / n)
        
    return np.mean(sku_costs)

# Example Usage during model tournament
spec_score = calculate_spec_grouped(y_test, y_pred, test_ids)
print(f"SPEC Optimizer Score: {spec_score:.4f}")

Building the Analytical Pipeline

01

Quantifying Volatility & Categorization

Identified the "Vital Few" using Pareto ABC Classification (Top 20% Revenue = Class A) to mathematically enforce tiered service levels. Quantified baseline volatility using Category-specific RMSE and identified the "Capital Gap" between current stock and model-predicted needs.

02

Pivoting from Stats to Dollars (SPEC Scorer)

Initially evaluated using symmetric RMSE. However, an overstock of $5 shouldn't be treated equally to a stockout of $500. We developed a custom SPEC (Stock-keeping-oriented Prediction Error Costs) Scorer, penalizing stockouts at 0.75 and overstocks at 0.25 to actively prioritize high-margin revenue protection.

03

Data Architecture Migration

Migrated from a flat-file structure to a Star Schema with Fact (`inventory_fact`) and Dimension (`product_dim`, `store_dim`) tables to prevent Aggregated Measure Inflation. This ensured data integrity and allowed for sub-second performance in Tableau for "What-If" parameter tuning.

Strategic Roadmap

  • • Deploy the "Restock Radar" thresholds for all Class A items to maintain a 99% service level mandate.
  • • Use the Price Index tool to trigger smart liquidations specifically when we are priced higher than competitors.

SLA Leverages

  • • Dynamically link safety stock buffers to lead-time constraints to expose exactly how much capital is tied up locally.
  • • Use Lead Time Sensitivity model to negotiate faster delivery with vendors (e.g. Furniture/Electronics) to free up trapped capital.

Technical Toolkit

Python 3.11+ XGBoost & LightGBM Tableau Dimensional Modeling

Analyst Insight

"The symmetry trap is real. Evaluating business models with metrics like RMSE treats an expensive stockout equally to a minor overstock. Pivoting to dollar-weighting directly changed the strategy and protected core revenue."

Github Repository

Questions on this Optimization?