KatInterview

Optimize Perishable Food Stocking Under Asymmetrical Failure Costs

Machine LearningModel answer
HardModel answerMachine Learningmachine-learningdemand-forecastingprobabilistic-modeling

Last updated

Design an end-to-end ML and inventory system to predict demand distributions and output cost-optimal daily stocking levels under asymmetric waste and stockout penalties.

Scenario

An enterprise catering and retail food service operates 1,200 commercial cafeterias. Each site sells approximately 500 perishable items daily (e.g., prepped wraps, sushi, cold-pressed juices, hot entrées). These items have brief shelf lives ranging from 24 to 72 hours.

Currently, local managers place daily orders based on static rules of thumb or subjective guessing. This creates two major operational failures: high spoilage losses (wasted capital and sustainability penalties) and frequent afternoon stockouts (lost revenue, lower customer trust).

You are tasked with designing an end-to-end Machine Learning system that predicts full daily demand distributions per item/location and converts those probabilistic forecasts into optimal replenishment orders.

System Requirements

Functional Requirements

  1. Probabilistic Demand Forecasting: Compute daily demand distributions (not single-point averages) across a 7-day rolling window for every (location_id, item_id) combination.
  2. Censoring Correction: Adjust historical training labels where stockouts truncated observable sales below actual customer demand.
  3. Cost-Optimal Inventory Policy: Map forecast distributions to specific order quantities by balancing shelf life, supplier lead times, waste/spoilage costs ($C_w$), and stockout penalties ($C_s$).
  4. Actionable Insights & Explanations: Provide site managers with clear driver signals (e.g., local events, weather changes, calendar seasonality) explaining why a stocking target was adjusted.

Non-Functional & Operational Scale

  • Scale: 1,200 locations $\times$ 500 items = 600,000 active daily time-series. The nightly batch pipeline must run ingestion, un-censoring, feature engineering, model inference, and inventory policy optimization within a 90-minute window before early-morning logistics dispatch.
  • Interactive Latency: An ad-hoc scenario simulation API (e.g., testing custom promo discounts or severe weather overrides) must respond in < 400 ms.
  • Adaptability: The pipeline must continuously handle menu updates, dynamic pricing changes, and local promotional events without requiring manual model re-architecting.

What Your Design Should Cover

  1. Data Pipeline & Censored Demand Handling: Methods to recover true underlying demand from truncated point-of-sale (POS) logs (e.g., intraday scaling, Tobit maximum likelihood, survival analysis).
  2. Probabilistic Modeling Architecture: Model designs (e.g., Quantile Gradient Boosted Trees, DeepAR, Temporal Fusion Transformers) capable of outputting parametric or non-parametric probability distributions.
  3. Inventory Optimization Framework: Formulation of the generalized newsvendor problem under multi-period shelf life, non-zero lead times, packaging constraints, and asymmetric financial loss functions.
  4. Validation Strategy & Metrics: Backtesting setup preventing temporal leakage, distribution-focused evaluation metrics (Pinball Loss, CRPS), and business KPIs (Fill Rate, Spoilage Ratio).
  5. Human-in-the-Loop & Deployment Strategy: Operational fallback triggers, manager overrides, shadow deployments, and phased rollout protocols.

Hints

Hint 1

Consider how POS timestamps (e.g., stock hitting zero at 1:00 PM vs. 7:30 PM) provide structural clues about truncated demand.

Hint 2

Point forecasts (like standard MSE regression) implicitly optimize for symmetric loss, which fails when waste cost differs significantly from stockout cost.

Hint 3

For multi-day perishable inventory with non-zero lead times, simple static Newsvendor critical fractiles are insufficient; sample-path simulation can capture complex inventory aging dynamics.