Apparel & retail · Commercial analytics
A weekly pipeline decomposes gross profit down its driver tree and attributes the variance in dollars. Deterministic math wherever a derivation exists; models only where one does not.
Merchants at a global apparel retailer could see that gross profit had moved. What they could not see was which of the fifteen-odd levers underneath it had done the moving, or how many dollars each was worth. The driver tree existed — on a slide. Reconstructing it against actuals was several days of analyst work, by which point the next week had closed.
Deterministic math wherever a derivation exists; predictive models only where one does not. That boundary is the architecture, and drawing it explicitly — rather than reaching for a model at every level — is what makes the output defensible in a meeting.
The tree has four levels and three different decomposition methods:
Levels 1 and 2 are correct by construction, not by validation — the arithmetic cannot disagree with the ledger. Only level 3 is estimated, and it is labelled as such. A merchant who distrusts the model can still trust the factor totals above it.
The two methods have to produce one number. LMDI gives each level-2 factor a dollar figure. TreeSHAP gives each level-3 lever an importance score for the factor above it. Each lever's dollars are then its share of the SHAP magnitude within its parent factor, multiplied by that factor's LMDI dollars — so lever dollars sum to the factor total, and the factor totals sum to the change in gross profit. The attribution reconciles at every level.
Not every movement deserves a narrative. Anomalies are scored with a modified Z-score — median and median absolute deviation rather than mean and standard deviation. Standard Z is the obvious choice and the wrong one here: retail is seasonal and spiky, and a single promotional week drags the mean enough to hide the next month's genuine anomalies. The median-based version does not move. Scores bucket into four bands, from monitor-only through to immediate escalation.
Every node gets a composite score across four dimensions: dollar attribution, anomaly severity, how well the model explains that lever, and — the one worth stealing — actionability. A lever the merchant can pull this week scores full marks; one they partly influence scores half; a structural lever like door count scores zero.
This matters more than it sounds. Pure dollar ranking surfaces the biggest number, which is frequently something nobody can act on. Weighting for actionability means the top of the list is a to-do list rather than a post-mortem.
The system also reads the shape of the ranking. When most of the top causes route through the same part of the tree, it says so before the detail: if they run through demand it is a volume story; through price realisation, a pricing story. Merchants get the headline before the fifteen-row table.
The driver tree is a graph, so it is stored as one. A weekly pipeline runs at fiscal close: full refresh from the warehouse, anomaly and variance computation, graph population, then model inference. The agent that answers questions traverses the graph — it holds no warehouse credentials and recomputes nothing. Every figure it quotes was written by the pipeline and is traceable to the run that produced it.
Prompts and responses are both screened before and after the model call, for injection, personal data and harmful content. The screening sits outside the agent, so it cannot be prompted away.
The models train on roughly a hundred and twenty chain-week rows. That is a small dataset by any standard, and it constrains how many features can be used without overfitting — the cross-validated fit is strong, but strong fit on a small sample is a reason for care, not confidence. Moving to store-week granularity takes the training set into the tens of thousands and is the single biggest improvement available.
Two of the four multiplicative factors have models; the other two are waiting on cost and inventory features that do not yet exist in the extract. We scoped them out rather than proxying them, because a lever with an invented attribution is worse than a lever marked "not yet explained".
Tell us what system the answer lives in and who needs it. We'll reply with a view on whether it's a two-week assessment, a five-week pilot, or something else.