ELAI S.r.l.

Inventory and AI: why the most accurate forecast can choose the wrong order

From asymmetric loss to the optimal quantile: a discrete example, costs, capacity constraints, and distortion from censored sales.

Inventory and AI: why the most accurate forecast can choose the wrong order

Abstract: predicting a mean and choosing a quantity are different problems

A network minimizing squared error can estimate mean demand perfectly and still suggest an economically poor order. The model is not necessarily at fault: shortages and surpluses can have different costs. In a synthetic example, the MSE-optimal mean is 78 units with expected cost EUR 190; the economically relevant quantile chooses 200 units with cost EUR 122, despite much worse MSE. We derive the decision threshold, compare alternatives, and show how stock-limited sales can distort training targets.

The setting is one replenishment period for a perishable product, without interim orders, substitution, or fixed costs. Quantities are units, costs euros per unit, and demand nonnegative. All numbers are explicitly hypothetical and calculated in Python, not EL-AI savings. Prerequisites are expectation, cumulative distributions, and convexity. The result concerns a bounded decision model, not a complete inventory policy.

1. Write the loss before choosing the model

Let D be demand and Q available quantity. A shortage costs c_u per unit and an excess c_o. Loss is c_u(D−Q)_+ + c_o(Q−D)_+, with z_+=max(z,0). These are incremental costs, potentially incorporating lost margin and net leftover cost. Do not add purchasing costs or revenues again if already included in the coefficients. We directly set c_u=9 and c_o=1 and minimize expected loss.

L(Q,D)=c_u·max(D−Q,0)+c_o·max(Q−D,0) R(Q)=E[L(Q,D)] τ=c_u/(c_u+c_o)

For continuous demand, slightly increasing Q costs c_o when D<Q and saves c_u when D>Q. Risk derivative is (c_u+c_o)F(Q)−c_u, zero at F(Q)=τ. For discrete demand the derivative may fail at jumps; the condition is F(Q−)≤τ≤F(Q). The smallest quantile reaching τ is optimal, but a flat CDF at exactly τ can produce multiple optima. No normal-demand assumption is needed.

2. A fully calculable discrete example

Set P(D=40)=0.50, P(D=80)=0.35, and P(D=200)=0.15. Mean demand is 40·0.50+80·0.35+200·0.15=78. The CDF is 0.50 at 40 and 0.85 at 80, so its 0.90 quantile is 200. Ordering 80 gives expected excess 0.50·40=20 and shortage 0.15·120=18: cost 20+9·18=182. Ordering 200 removes shortages but leaves expected excess 0.50·160+0.35·120=122. We compare the specified cost, not leftover units alone.

QCost EURMSE units²Mean shortage
40342.04400.038.0
78190.02956.019.0
80182.02960.018.0
120162.04720.012.0
200122.017840.00.0

The script enumerates Q from 0 to 240 and verifies different minima: MSE at 78, cost at 200. It also checks every integer difference R(Q+1)−R(Q)=10F(Q)−9. From 80 through 199, the difference is −EUR 0.5: each extra unit lowers expected cost. From 200 onward it is +EUR 1. This independent check exposes convexity and explains the minimum.

Expected losses on the same synthetic distribution. Cost and MSE minima differ because objectives differ; curves are not trained-model performance.
Expected losses on the same synthetic distribution. Cost and MSE minima differ because objectives differ; curves are not trained-model performance.

3. Connecting the quantile to the AI objective

Pinball loss ρ_τ(D−Q) weights underprediction by τ and overprediction by 1−τ. Our economic loss equals (c_u+c_o)ρ_τ(D−Q). A model conditioned on x can learn the relevant quantile through this loss if data, representation, and optimization allow it. Changing architecture while retaining MSE still targets the conditional mean. In our example MAE also cannot decide: every Q between 40 and 80 has MAE=38 but different economic costs.

ρ_τ(z)=τ·max(z,0)+(1−τ)·max(−z,0) L(Q,D)=(c_u+c_o)·ρ_τ(D−Q)

Reducing shortage cost to 4 with c_o=1 gives τ=0.80 and smallest optimum 80. Equal costs give τ=0.50, making all of [40,80] optimal. With capacity capped at 120 units, the original constrained optimum is 120 at cost EUR 162. Ordering 200 cannot ignore capacity. With lot sizes, shared multi-product budgets, or fixed costs, separate item quantiles may not solve the overall problem.

4. Service levels and invisible demand

τ=0.90 does not mean exactly 90% of periods avoid shortages. The discrete distribution jumps from F(80)=0.85 to F(200)=1. Cycle service level P(D≤Q) also differs from fill rate 1−E[(D−Q)_+]/E[D]. At Q=80 they are 85% and 76.9231%: rare high-demand periods contain many missing units. Even two “service” metrics can guide different choices unless denominators are explicit.

Suppose historical stock was always capped at 80. Recorded sales S=min(D,80) are 40 half the time and 80 otherwise, losing the distinction between demand 80 and 200. The sales 90% quantile is 80 with apparent cost only EUR 20, versus true cost EUR 182 on latent demand. More training epochs do not solve a censored target. Demand 1000 during stockouts would produce the same sales history, so sales alone cannot identify the tail.

A real application needs stock availability over time, stockout indicators, and an explicit strategy for unobserved demand. Evaluation needs decision-consistent temporal splits, stated costs, and simple-policy baselines. Future leakage or censored sales treated as full demand can mislead offline evaluation. This analysis trains no model: it specifies what one should learn and how to measure its usefulness.

5. How fragile is a quantile learned from little data?

So far the distribution was known. With twenty independent observed days, the empirical 90% quantile is the eighteenth ordered demand. If at most two days have demand 200, that quantile cannot exceed 80. Their count K is binomial with n=20 and probability 0.15. Exact P(K≤2), summing three binomial terms, is 0.404896278. About 40.49% of these small samples would therefore not suggest 200, even without censoring or optimizer error. This is sampling uncertainty in the tail, distinct from stock-limited-sales bias.

P(K≤2)=Σ_(k=0)^2 binom(20,k)·0.15^k·0.85^(20−k) R(Q+1)−R(Q)=0.85−0.15·c_u, 80≤Q<200, c_o=1

Cost coefficients also deserve sensitivity analysis. Between 80 and 200, increasing Q helps only if c_u>0.85/0.15=17/3 euros per unit. The decision switches sharply although expected cost is continuous: below that value 80 is preferable, above it 200, and at equality every intermediate quantity has the same cost. Estimating c_u=4 when its actual value is 9 selects 80, losing EUR 60 in expected cost per period relative to this model’s optimum. This is a theoretical policy difference, not a projected commercial saving.

For a conditional model, seasonality, promotions, and lead times must be available before ordering. Learn demand over the decision’s protection period, not necessarily next-day sales. Context-dependent costs can also change τ(x). One output trained at the 90% quantile does not automatically answer a new cost ratio: estimate multiple quantiles or a distribution, and evaluate without selecting the model on the same period used to claim its advantage.

6. Conclusion and methodological source

MIT’s newsvendor notes develop the marginal decision and cost ratio; we consulted their derivation and discrete and continuous examples. Our numerical case is separate. The result does not say more stock is always better: the right quantile depends on costs and constraints, while the right data must represent demand rather than stock-limited sales. Before comparing AI architectures, check that the objective matches the business decision.

MIT OpenCourseWare, D-Lab: Supply Chains (Fall 2014), Newsvendor Inventory Problem, derivation and worked examples.

demand = [(40, .5), (80, .35), (200, .15)]
def cost(q):
    return sum(p*(9*max(d-q,0)+max(q-d,0)) for d,p in demand)
print(sum(d*p for d,p in demand))
print(min(range(241), key=cost))
for q in [40,78,80,120,200]:
    print(q,cost(q))

Code, data, and instructions · JSON. Educational calculations executed with Python 3.14.0; figures with Matplotlib 3.11.2. AI-assisted analysis, without claiming peer review or human review. Original illustrative ImageGen cover: it does not document EL-AI people, premises, or installations. Sources accessed 24 September 2026.