Case Study 10 · Live, 25 November 2026

Recommendations and Promotions for a B2B Wholesaler

Recommendations · PyTorch · Implicit ALS · Segmentation · Imputation · Assortment optimization · Uplift modeling · PySpark · Python · 25 tests

The business question

A wholesaler that sells through an ordering platform serves thousands of small retailers. Each week it has to decide what to put in front of each one: the products it reorders, the ones it has never tried, the shelf a whole group of similar shops sees first, and which retailers get a promotion that costs money. Part of the orders also arrive without an account number, and those sales vanish from every customer history built on top of them.

This case answers the five questions on one public data set, with the same rule for all of them: every model learns from the past and is scored on a period it never saw.

The data

Online Retail II (Chen, 2012, UCI Machine Learning Repository, CC BY 4.0) holds every invoice line of a UK online seller of gift-ware from 1 December 2009 to 9 December 2011: 1,067,371 lines, 39,516 sale invoices, 5,852 customers in about 40 countries and 4,707 products. The data set notes that many of its customers are wholesalers, which makes it one of the few public B2B order logs.

It is also messy in the ways real order data is, and each problem is counted before anything is modeled. 19,494 lines are cancellations; 34,335 are exact duplicates, 22,844 of them because the two sheets of the workbook both contain 1 to 9 December 2010; 6,093 carry codes that are not products (postage, bank charges, manual adjustments); 6,207 have a zero or negative price; 7,881 have a price more than ten times above or below the usual price of the same product, and are kept but flagged. After cleaning, 1,003,214 sale lines remain.

The largest gap is the customer: 22.6% of the sale lines, 13.1% of the revenue, have no customer number.

Method, and why this one

One cutoff for everything. Models learn from the orders before 9 October 2011 and are scored on the last 61 days. Their settings were chosen on the 61 days before that, so the test window was used once. 12.5% of the revenue in the test window comes from products never sold before the cutoff, which no model here can recommend.

Two recommendation tasks, not one. For a wholesaler, most of the next order repeats past orders. Recommending “what you already buy” and “what you have never bought” are different jobs, and they are scored separately. Five models compete: popularity in the last 90 days, “buy again”, item-to-item co-purchase, implicit ALS, and a sequential model in PyTorch that reads each customer’s orders in sequence with a GRU and scores every product for the next order. Each recommendation shows the customer’s own product it is most often bought with, so a sales rep can explain it. Scores are Recall@10 and NDCG@10 with 95% bootstrap intervals over customers.

Segments that a manager can name. Customers are grouped by recency, frequency, revenue, basket size and range of products, with k-means and the number of groups chosen by silhouette. The names come from the medians of each group.

Imputation evaluated, not assumed. To see whether orders without a customer number can be attributed, the number is hidden on orders where it is known, and each basket is matched to the purchase profiles of known customers in the same country.

A shelf with variety. For each segment, a mixed-integer program picks the 30 products with the highest recent segment revenue with at most 4 from any product family (families come from the product descriptions, since the data has no category). It is compared with the segment’s top sellers and the overall top sellers on what the segment bought in the test window.

Promotions on a semi-synthetic experiment. The data has no promotions, so a randomized voucher is simulated on the real customers: each customer’s spend without the voucher is the real spend in the test window, and the voucher’s effect is a known function of the customer’s real history (it brings back lapsed customers who used to spend, and gives away a discount to frequent buyers who would have ordered anyway). Because the true effect is known for every customer, any targeting rule can be scored exactly. This measures whether uplift models find who responds; it does not show how this wholesaler’s customers respond to real promotions.

Spark, with a parity test. The cleaning rules and an implicit ALS are also written in PySpark. CI runs them on a sample of the raw file and fails if Spark and pandas disagree on any sale line.

Result

Most of the next order is a reorder. Scored on everything customers bought in the test window, the simplest rule wins by far: offering each customer its own most frequent products (“buy again”) reaches an NDCG@10 of 0.341, against 0.260 for the sequential model, the best of the learned ones. A recommender that skips reorders leaves the easiest value of a B2B platform on the table.

Model, all products (2,041 customers) Recall@10 NDCG@10 (95% interval)
Buy again 0.327 0.341 (0.329 to 0.353)
Sequential GRU (PyTorch) 0.243 0.260 (0.249 to 0.271)
Implicit ALS 0.195 0.196 (0.187 to 0.205)
Item-to-item (co-purchase) 0.160 0.163 (0.154 to 0.172)
Popularity (last 90 days) 0.100 0.102 (0.096 to 0.109)

For products the customer has never bought, the learned models earn their place. The sequential model (0.071) and implicit ALS (0.070) tie: the difference, 0.002, has an interval from -0.004 to 0.007. Both beat co-purchase (0.059) and popularity (0.045). The numbers are low because the task is hard: ten tries to find, among 4,529 products, the few a customer will buy for the first time in the next two months.

Model, products new to the customer (1,917 customers) Recall@10 NDCG@10 (95% interval)
Sequential GRU (PyTorch) 0.073 0.071 (0.066 to 0.077)
Implicit ALS 0.071 0.070 (0.064 to 0.075)
Item-to-item (co-purchase) 0.063 0.059 (0.054 to 0.065)
Popularity (last 90 days) 0.048 0.045 (0.041 to 0.049)

Three segments, and one of them is the business. Silhouette picked three groups. A third of the customers, active (a median of 27 days since the last order and 9 orders), bring 83.5% of the revenue before the cutoff. Almost half had not ordered for a median of 295 days.

Segment Customers Share of revenue Median days since last order Median orders Median revenue
Top, active 1,821 83.5% 27 9 £3,060
Mid-value, lapsed 2,543 12.9% 295 2 £560
Low-value, lapsed 1,108 3.5% 312 1 £201

Orders without a customer number should not be attributed automatically. With the number hidden on the 4,790 orders of the test window, the basket matching puts the right customer first 22.5% of the time and in the top ten 46.3% of the time, among customers seen before, against 4.4% and 11.1% for the busiest customers of the same country. It narrows the search, but even its most confident quarter of matches is right only 24.1% of the time, and 12.2% of the orders come from customers never seen before. The orders without a number also look different: the typical one has 20 lines against 15, at a typical unit price of £3.36 against £1.97, which points to another sales channel rather than known accounts that did not log in. The pipeline keeps them out of the customer histories and turns the matches into a review queue: in the test window, 29 of the 227 orders without a number reach the confidence of the top quarter.

A shelf with variety holds up where it matters. For the top segment, the optimized shelf of 30 products covered 12.6% of what those customers bought in the test window and reached 76.8% of them, against 11.6% and 72.6% for the segment’s top sellers and 11.9% and 72.3% for the overall top sellers, with 12 product families instead of 7 and 9. In the two lapsed segments the cap costs a little revenue coverage (8.1% against 8.5%, and 4.5% against 4.9%). In every segment, the shelf that covers the most revenue is one built for that segment.

Promotion targeting: the models pay off on small budgets. In the simulated voucher test on the 5,472 customers with history (10 replications), giving the voucher to the 20% of customers the X-learner ranks highest brings £39,590 of true incremental revenue, against £21,940 for random targeting, £23,488 for the top spenders and £23,892 for the most lapsed customers; an oracle that knows every effect would reach £102,578. Learning who responds is hard because spend varies by orders of magnitude between customers. Dividing the outcome by each customer’s past monthly revenue before fitting, which keeps the estimate unbiased under random assignment, raised the X-learner’s area under the gain curve from 13% to 23% of the oracle’s.

Over the whole range of budgets, the rule “most lapsed first” still covers the most area, 45% of the oracle’s, because the simulated effect was built around lapsed customers and the rule happens to match it. With an effect twice as large the X-learner reaches 41%; with four times as large, the three learners on the scaled outcome pass the rule (the X-learner reaches 61%). For a real campaign: a randomized test on about 5,500 customers already pays off when the budget is small and targeted; ranking the whole base needs a larger effect or a larger test.

Try it

Pick a customer to see what the models would suggest and whether the customer bought it in the next 61 days, a segment to see its shelf, or a promotion budget to see how much incremental revenue each targeting rule brings in the simulated experiment.

Limits

The data covers one seller of gift-ware in 2009 to 2011, mostly in the UK; the numbers are evidence about the methods, not about any other company. The promotion experiment is simulated on real customers, so it tests the targeting methods, not real price sensitivity. Products launched in the test window cannot be recommended by any of these models; a content-based model on product attributes would be the next step. The Spark job runs locally in CI on a sample; it has not run on a cluster.

Applied to your business

For a distributor, a wholesaler or a B2B ordering platform, the same pipeline runs on your order history: suggested orders per customer, with the reason next to each item; segments with a shelf per segment; a targeting rule for each promotion, tested before the budget is spent; and a review queue for orders without an account. It starts with the Data & AI Diagnostic and runs in your environment.

Code

github.com/rhozon/b2b-retail-recommender

With Python 3.11 or later and the workbook in ~/data/online-retail-ii:

pip install -e ".[dev]"
pytest -v
python -m b2bretail.cli --out results

The suite has 25 tests. CI runs them on every push, and a second job with Java 17 runs the Spark parity tests and the Spark job.

References

  • Athey, S. and Imbens, G. (2016). Recursive partitioning for heterogeneous causal effects. Proceedings of the National Academy of Sciences, 113(27), 7353-7360. doi:10.1073/pnas.1510489113
  • Chen, D. (2012). Online Retail II. UCI Machine Learning Repository. doi:10.24432/C5CG6D
  • Hidasi, B., Karatzoglou, A., Baltrunas, L. and Tikk, D. (2015). Session-based Recommendations with Recurrent Neural Networks. arXiv. doi:10.48550/arXiv.1511.06939
  • Hu, Y., Koren, Y. and Volinsky, C. (2008). Collaborative Filtering for Implicit Feedback Datasets. 2008 Eighth IEEE International Conference on Data Mining, 263-272. doi:10.1109/ICDM.2008.22
  • Künzel, S. R., Sekhon, J. S., Bickel, P. J. and Yu, B. (2019). Metalearners for estimating heterogeneous treatment effects using machine learning. Proceedings of the National Academy of Sciences, 116(10), 4156-4165. doi:10.1073/pnas.1804597116
  • Sarwar, B., Karypis, G., Konstan, J. and Riedl, J. (2001). Item-based collaborative filtering recommendation algorithms. Proceedings of the 10th international conference on World Wide Web, 285-295. doi:10.1145/371920.372071
WhatsApp ↑