Technical

Forecast-based allocation

Forecasting store-by-store demand for a product with no history. With the same stock, LightGBM beats both the plan and the store's past share. The oracle, which knows the shares almost perfectly, gets less far ahead than you would think.

Initial Allocation · 4 / 6

In the last article we defined the lookalike product by hand. Calibration told us that the best “lookalike” was hardly a lookalike at all: the store’s coarse past share. In this article we stop defining similarity and teach it to a model.

The skeleton of the method is the same as in the last article. The candidate stores, the packs to send and the apportioning are the same; the only thing that changes is the stores’ share. In this article too every arm sends the same stock: uncapped, without holding back any extra stock in the warehouse.

A product with no history

A new product has no sales of its own. But for hundreds of products in past seasons we know what each store sold in the first six weeks. We turn that into a table: each row is a past (product, store) pair, and the target is that pair’s demand in the first six weeks. The demand is corrected for days out of stock, as in the last article.

Next to each row we put three kinds of information: the attributes on the product’s record, the store itself, and what kind of product the store has sold in the past.

In the code the feature list is this:

# initial_allocation/forecast.py
OPTION_CATEGORICAL = ("category", "subcategory", "price_segment", "fit", "fabric", "colour", "pattern",
                      "gender")
OPTION_NUMERIC = ("wave", "list_price", "initial_buy")
MIX_FEATURES = ("subcategory", "fit", "price_segment")
SHARE_COLUMNS = [f"share_{c}" for c in MIX_FEATURES]
FEATURES = [
    *OPTION_CATEGORICAL, "season_type", *OPTION_NUMERIC,
    "store_type", "store_region", "store_city", "area_sqm", "capacity",
    *SHARE_COLUMNS,
]

We fit a single LightGBM model to this table. The objective is Poisson, because demand is a count. The model learns only from seasons closed by the decision day; spring-summer and autumn-winter are not separate models, the season is a feature.

When a new product arrives, a row is built for each candidate store: the product’s attributes, the store’s features and the store’s past mix. The model forecasts a demand for each row. The store’s share is its forecast divided by the candidates’ total forecast.

The model must not see its own answer

There is one place where care is needed. If we work out the “what the store sold in the past” features from the whole training table, every row sees its own target inside its features. The model looks better in training than it is, and does worse than expected on a new product, because a new product’s demand is not in the past.

So in training we split the products into folds. A fold’s rows take the store’s mix only from the products in the other folds:

# initial_allocation/forecast.py (training_features)
for k in np.unique(fold):
    inside = fold == k
    share[inside] = _shares(t[inside], mix(t[~inside])).to_numpy()

At forecast time the mix is worked out from the whole history; the new product is not in that history anyway.

Let us also be accurate about what the model relies on. The model has never seen this product. Nor did it pick out its lookalikes one by one. What it saw was which store sold how much of what kind of product in the past.

In calibration

We chose the model’s settings without looking at the game season too, in the previous spring-summer season. With the same share error (defined in the last article; 0 means identical shares, 1 completely disjoint):

Share error
Equal0.292
Lumoda (plan share)0.236
Store’s past share0.235
Model0.197

In calibration the model takes a much bigger step than the gap between the plan and the store’s past share. The real question is what that turns into in the field, at the end of the season.

In the game season, with the same stock

We add one more arm: the oracle. The oracle knows each store’s true demand in the first six weeks. That knowledge was measured in another run of the same customer stream; so the oracle is the answer to what would happen if we knew the hidden truth. It gives shares in proportion to that demand; it has not been proved that this is the best allocation. There is no such arm in real life. It is here to show what would happen if we knew the shares almost perfectly.

Five arms, the same initial allocation, the same season:

Share errorAvailabilityStock left at the end of the seasonFull-price STRSTR; the percentage of the stock a store received that has sold. In fashion retail the figure that matters is the part sold at full price.Gross profit
Equal0.29767.62%22.23%51.33%TRY 519,113,339
Lumoda (plan share)0.23568.98%19.77%52.69%TRY 534,433,105
Store’s past share0.22969.51%19.65%52.85%TRY 535,147,736
Model0.17170.41%17.74%53.99%TRY 550,029,513
Oracle0.00671.23%17.06%54.41%TRY 563,610,800

The order is as expected: oracle, model, store’s past share, plan, equal. With the same stock, on the published stream, the model is 1.43 points ahead of the plan in availability. Stock left at the end of the season is 2.03 points lower, and gross profit TRY 15,596,408 higher.

We repeated the same comparison on four more customer streams; on every path the products’ success is the same and only the customer stream changes. On five paths out of five the order is the same; at the median of the paths the model is 1.45 points ahead of the plan, and the oracle 0.82 points ahead of the model.

Let us measure the gap between the oracle and the plan by how much of it the arms close. The store’s past share closes 24% of the availability gap and 3% of the share error gap. The model closes 64% in availability and 28% in share error.

Note the gulf between the two numbers. The model closes only a little over a quarter of the share error, but nearly two thirds of the availability. The first improvement in the share error brings a lot to availability; the return on bringing the share closer to perfect keeps shrinking.

Among the pairs that received an initial allocation, those that could not sell even a fifth of what they first received in four weeks number 1,065 (19.9%) under the plan and 940 (17.6%) under the model; under the oracle, 441 (8.2%).

The oracle’s limit

The oracle’s share error is 0.006. Almost perfect: every store gets stock in proportion to its demand. Even so, it is only 2.25 points ahead of the plan in availability.

This is one of the most important findings of the series. Splitting the stock correctly between stores does not solve the rest of the season. Even under the oracle, the share of the loss that comes from sizes is at the same level as under the plan: 42.8% against 42.3%. The oracle picks the store correctly, but it does not change the sizes in the pack. Replenishment, repeat orders and markdown during the season all work by the same rules. Even inside the oracle’s 2.25 points there is a part that comes from the reaction of repeat orders and markdown: 1.96 points from the allocation itself, 0.29 points from that reaction. We measure the cost of the size mismatch in the sixth article.

“Knowing the share correctly doesn’t solve the whole season,” says Pars. “But now we know what knowing the share almost perfectly, with the same stock, is worth: this much.”

Back to the dress

Remember the first article’s dress. Lumoda had sent 448 units to Izmir 4 and 112 to Erzurum 2. Using only what was known that night, the model would have proposed 119 units for Izmir 4: 26.6% of what Lumoda sent. For Erzurum 2, 609: 5.4 times Lumoda’s.

The model did not know this dress. What it knew was how Izmir 4 and Erzurum 2 had sold this kind of product in the past. Again, a single dress proves nothing; the table above gives the difference over the whole season.

What is hard in your data

The first thing is attribute data. Everything this model sees comes from the product’s record: category, fit, fabric, pattern, price segment. In a real ERP these fields are often a mess. The same fit is entered under different names, the fabric field is left blank, the price segment was never defined. The model can only be as good as that record. At Lumoda the record is complete; in yours, the first job is probably to clean it up.

The second is the plan and the sales not being kept in the same hierarchy. At Lumoda the plan, the sales and the product use the same category tree: the plan’s category matches the product’s category one to one. In many chains the plan is kept in another system, with another category tree. Until you match the two, you can measure neither the plan nor the model.

And this article has a lesson of its own. However much the share improves, how far even the oracle can get is limited. The rest is decided by what happens after the initial allocation. In the next article we look at the first of those: the stock held back in the warehouse.

By Sabri Suyunu