Project 8 of 10, for Yahya
Customer Segmentation
Sort a wholesaler's 440 real customers into segments by what they buy, with k-means from scratch and k at the elbow, then find the two directions they differ along most with PCA from scratch, and check both against what the clusters never saw.
Sign up free to open itLog in
Act 6 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- YahyaA wholesaler in Portugal published a year of spending for 440 customers, but there are no labels on what they are.
- YahyaIt's six columns of money and there's a story in there somewhere. What kinds of customer have they got?
- YahyaWe group them first, then find the two numbers that say most about how they differ.
- PaulAnd then you say in words what each group is, because that part's down to you.
customers.csv holds 440 real customers of a wholesaler: a year's spending on fresh food, milk, grocery, frozen food, detergents and paper, and delicatessen, and whether each is a hotel, restaurant or cafe (horeca) or a shop (retail).
In segments.py:
- Take the log of the spending and standardise each column.
- Sort the customers into groups, from scratch, with nobody saying what the groups are: the best of ten random starts for each number of groups from 1 to 8, then the number chosen where an extra group stops helping, and checked against scikit-learn.
- Describe each segment: how many customers, what share are shops, and which goods it buys more of than average.
- Find the directions the customers differ along most, from scratch, and say how much of the difference the first two hold and which goods each leans on.
k inertia 1 2640.0 2 1848.0 3 1558.0 4 1391.9 5 1272.8 6 1182.7 7 1102.7 8 1032.1 Chosen k: 2 Segment 1: 251 customers, 3% retail, above average on fresh, frozen Segment 2: 189 customers, 71% retail, above average on milk, grocery, detergents_paper, delicatessen scikit-learn agrees: True Component 1 explains 44%: milk, grocery, detergents_paper Component 2 explains 27%: fresh, frozen, delicatessen
What you learn
What's in it
- Groups nobody named
- Every point to every centre
- One step
- Tight groups, and bad starts
- How many groups?
- Taming lopsided money
- How Paul would sort it
- Find the segments
- How columns move together
- Directions that don't turn
- The directions that don't turn
- The directions that matter most
- How Paul would squash it
- Fix Caitlin's version
- Two axes that matter
- Ship it