Supervised clustering · a worked example at an animal shelter
Cluster the reasons.
Supervised clustering lets a good-enough model tell the clustering what matters. Here it turns a gut-feeling rule at an animal shelter into five kinds of animal, each needing a different kind of help.
scroll slowlyThe request
Which of our animals will wait a long time for a home, and what would help each of them?
Tails & Whiskers, a made-up shelter, has a few volunteers, a website and one photographer on Saturdays. About half of its animals find a home within two weeks (49%); the rest can wait for months. Every animal on this page is simulated.
The rule on the table
Under two years old → they'll be fine.
Everyone else → extra help.
one variable, and everyone loves a puppy…
The approach
Cluster the model's explanations, not the animals
We proposed data-driven profiles instead. The obvious tool is clustering, and on the raw data it fails. The fix is one extra step.
Cluster the raw data
Reduce everything to two dimensions and look for groups. That step is sound: in high dimensions, density estimates degrade and HDBSCAN slows down, and the literature shows that reducing with UMAP first considerably improves clustering. But here you get one overlapping cloud. The shelter records fifty things about every animal, and most of them (kennel row, vaccination dates, the length of its name) have nothing to do with adoption. Clustering doesn't know what we're asking.
Ask a model first
A simple model predicts which animals find a home within two weeks. It only needs to be good enough to learn which features matter. SHAP then says, for every animal and feature, how far that feature pushes it towards a quick adoption or a long wait.
Cluster the explanations
Every feature is now in the same unit, and features that don't matter shrink to zero. Animals group by why they are adopted quickly or slowly, and the groups can be named.
Step one · the good-enough model
Gradient boosting: a hundred small trees, adding up
The model's job is to learn which features separate quick adoptions from long waits, not to be perfect.
Each tree asks a few questions
Gradient boosting builds small trees one after another (XGBoost here). Each new tree corrects the mistakes of the ones before it, and their answers add up to a score: the log-odds of a home within two weeks. These are the first three trees it learned: weight, age and the number of photos come up straight away.
Clearly better than chance
On animals it never saw, it ranks a quickly adopted animal above a slow one 82% of the time. As in real life, about one in six animals goes against its profile: a shy senior who finds a family on day one. We don't use its predictions: it's a lens on which features matter, and for that it only has to clearly beat chance.
Step two · SHAP values
Why the model says what it says, animal by animal
SHAP splits each animal's score into one contribution per feature. Starting from the average animal, the contributions add up exactly to the score.
89% a quick home, because it's a puppy
Start from the average animal. Being 7 months old pushes the score up the most; being small adds more. Every bar is in the same unit, so an age in years and a weight in kilos can be compared directly.
86%, for a different reason
Almost the same score, but here 9 photos in the listing do the work. The score alone would put A and B together; SHAP keeps them apart. And B falls outside the age rule: it would have been sent for "extra help" it doesn't need.
The matrix we cluster
One row of SHAP values per animal, each from a model that never saw that animal (out-of-fold). The five features that drive adoption spread out; vaccination dates, kennel row and the other unrelated columns sit at zero, so they drop out of the distance. This matrix, not the raw data, goes into the clustering.
Step three · what it does to the data
The same animals, three times
Each dot is a simulated animal. Keep scrolling and watch the same points move from the raw data to the SHAP matrix you just saw.
Intertwined
Plain clustering sees one cloud. Most of the 50 columns have nothing to do with adoption, and the ones with the biggest numbers (days since vaccination, up to 365) dominate the distance. Quick and slow adoptions sit side by side.
Quick and slow separate
Same animals, same settings. Once animals are described by what drives their adoption, the quick ones gather in their own groups.
Five reasons, five profiles
Three reasons to find a home quickly, two reasons to wait. The split between quick and slow is by design; the reasons inside each side are the finding.
Who has great photos
Colour the map by one raw feature at a time. The number of photos lights up the photogenic stars and no one else.
Who's young
Age marks out the puppies and kittens at one end and the shy seniors at the other. That is all the age rule can see; the easy companions and the photogenic stars are invisible to it.
No pattern, on purpose
Vaccination dates have nothing to do with adoption, so the model gave them no weight. It's the kind of column that drowns plain clustering.
The profiles
Five kinds of animal the volunteers can picture
Each cluster is named after the features that drive it. Three find homes on their own, for different reasons. Two wait, for different reasons too.
Photogenic stars
Easy companions
Shy seniors
Big and bouncy
Simulated animals: shares and adoption rates come from the 1,000 points above. Each profile comes with a short rule from a small decision tree, so volunteers can sort a new arrival without a model.
What it changes
The right help for the right animal, and a fair test
Help where it works
The age rule sends 73% of the animals for extra help, including the photogenic stars and easy companions who don't need it. A short rule per profile points the help at the two groups that wait.
The right kind of help
The profile says why an animal waits, so each gets its own plan: quiet meet-and-greets and foster homes for the shy seniors, training and more volunteer walks for the big and bouncy ones.
Saturday photos
Photos are the cheapest lever in the data. The photographer's Saturdays go first to the animals whose profile says a better listing would make the difference.
Profiles are a hypothesis until a test says otherwise. The next step: give the new kind of help to half of each waiting profile, at random, and compare days to adoption, with the measure fixed in advance.
A small change in method turns a vague question into profiles a team of volunteers can act on in a week.
It works anywhere a model can explain an outcome: why subscribers cancel, why machines fail, why students drop out. Explain first, then cluster the explanations.
Data: simulated for this page (tools/animal_sim.py): 1,000 animals, 50 columns of which 5 matter, five hidden groups, and noise so that about one animal in six goes against its group. Tails & Whiskers is made up. Model: XGBoost, with SHAP computed out of fold (AUC 0.82); maps: UMAP on the raw data and on the SHAP values, clusters: HDBSCAN. Method adapted from "Supervised Clustering for Subgroup Discovery" (ECML PKDD 2021); UMAP before clustering: Allaoui, Kherfi and Cheriet (ICISP 2020).
Comments
Sign in with GitHub to leave a comment or react.