AI Hints
Home›Data Science Tutorial›Products and Prices
Data Science · Lesson 37 of 101

What Sells Together

And what it really tells you.

⏱ 2 min read▶ Video at 1:04:16🎓 Free
Watch this lesson in the Data Science courseWatch on YouTube ↗Full Data Science course

A shop manager notices that lattes and muffins both sell well on the same days. So should they be sold as a bundle? It sounds obvious. But there's a trap here, and it catches a lot of analysts.

What Sells Together
From the video: What Sells Together
  • Lattes and muffins sell together
  • Should we bundle them?
  • There's a trap here

Correlated, but why?

We take one cafe, and make a table with one row per day, and one column per product. Then we see how closely latte sales move along with everything else, and what share each product takes. Run it. Everything moves together, with correlations of around point four. Does that mean people buy them together? No. On busy days, everything sells more. That's a confounder, and it's the customer traffic. Daily totals can't tell you what's in the same basket. For that, you need receipt level data.

pairs.pypython
import pandas as pd

sales = pd.read_csv("sales.csv")
day = sales[sales["store_id"] == 1].pivot_table(index="date", columns="product", values="units", aggfunc="sum")

print(day.corr().loc["Latte"].round(2).sort_values(ascending=False).head(4).to_string())

share = day.div(day.sum(axis=1), axis=0).mean().round(3).sort_values(ascending=False)
print(share.head(4).to_string())
Output
product
Latte         1.00
Espresso      0.43
Flat White    0.43
Mocha         0.39
product
Latte         0.259
Espresso      0.160
Flat White    0.130
Muffin        0.109

Measuring real pairings

With receipts, you can use three simple measures. Support is how often two items appear in the same basket. Confidence is, of the people who buy a latte, how many also buy a muffin? And lift compares that with what you'd expect from chance. A lift of two means that they appear together twice as often as you'd expect. Lift is the one to trust, because it removes the effect of items which are simply popular.

keyvalue
Supporthow often together
Confidencegiven one, the other
Liftcompared with chance
Lift above 1a real pairing

Summary

Daily totals move together, because busy days lift everything. Use receipts and lift. Next, the most powerful lever in any business. Price.

Key takeaways
  • Traffic is a confounder
  • You need basket data
  • Trust lift
Next up: Pricing and Discounts — does a sale really pay?