Sub topic 3
Counting how often cards are grouped together
This chapter assumes you can read percentages, know what a navigation menu is, and have run or read about a card sort. A similarity matrix is a table that shows, for every pair of cards, the share of participants who put both cards in the same group. Clustering is an algorithm that merges cards into larger groups based on that table.
Counting how often cards are grouped together
Building the similarity matrix
Each participant's sort gives you a set of groups. For each pair of cards, count the participants who placed both in one group, then divide by the total number of participants. The result runs from 0 to 1.
from itertools import combinations
from collections import Counter
sorts = [
{"Delivery": ["Shipping rates", "Track order"], "Help": ["Returns"], "Other": ["Gift cards"]},
{"Orders": ["Track order", "Returns", "Shipping rates"], "Extras": ["Gift cards"]},
{"Shipping": ["Shipping rates", "Track order"], "Returns and gifts": ["Returns", "Gift cards"]},
]
pair_counts = Counter()
for sort in sorts:
for group in sort.values():
for a, b in combinations(sorted(group), 2):
pair_counts[(a, b)] += 1
n = len(sorts)
for (a, b), count in sorted(pair_counts.items(), key=lambda item: -item[1]):
print(f"{a} + {b}: {count / n:.0%}")The pair "Shipping rates" and "Track order" appears in every sort, so it scores 100%.
Clustering the matrix and reading a dendrogram
Clustering the matrix and reading a dendrogram
Clustering works on distance, which is 1 minus similarity. Cards with high similarity have low distance. Average-linkage clustering merges the two closest groups at each step, and it measures the distance between groups as the average of all card-to-card distances.
import numpy as np
from scipy.cluster.hierarchy import linkage, fcluster
from scipy.spatial.distance import squareform
cards = ["Shipping rates", "Track order", "Returns", "Gift cards"]
similarity = np.array([
[1.00, 1.00, 0.33, 0.00],
[1.00, 1.00, 0.33, 0.00],
[0.33, 0.33, 1.00, 0.67],
[0.00, 0.00, 0.67, 1.00],
])
distance = 1 - similarity
Z = linkage(squareform(distance, checks=False), method="average")
labels = fcluster(Z, t=0.5, criterion="distance")
for card, label in zip(cards, labels):
print(label, card)A dendrogram is a tree diagram that shows the order of merges. The height of each merge is the distance at which the groups joined. To pick groups, draw a horizontal cut across the tree. Each branch the cut crosses becomes one group. The code above cuts at distance 0.5, which gives two groups: shipping and tracking together, and returns and gift cards together.
> Note: the cut height is a judgment call. Check the groups against participant category names before you trust them.
Measuring agreement in closed sorts
In a closed sort, participants place cards into categories you define in advance. Agreement is the share of participants who used the category you expected.
placements = {
"Track order": ["Orders", "Orders", "Orders", "Help"],
"Gift cards": ["Shop", "Orders", "Help", "Shop"],
}
expected = {"Track order": "Orders", "Gift cards": "Shop"}
for card, choices in placements.items():
agreement = choices.count(expected[card]) / len(choices)
print(f"{card}: {agreement:.0%} placed in '{expected[card]}'")Low agreement for a card means either the label is unclear or the card fits more than one place.
Turning results into a navigation structure
Work from the clusters and the participant category names together:
- Name each top-level group with the words participants used most often.
- Place cards that split evenly between two groups in both places, and note them for review.
- Keep the depth shallow at first. Two levels are easier to test than five.
Validating the structure with tree testing
Tree testing shows participants a text-only version of your draft hierarchy and asks them to find specific items. It checks the structure itself, without the visual design.
| Method | Question it answers |
|---|---|
| Card sort | How do people group these items? |
| Tree test | Can people find items in the draft structure? |
Limitations, biases and common mistakes
- Small samples give unstable percentages. A few participants can swing a pair's score widely.
- Card wording can lead participants. Use neutral, plain phrases.
- Participants may group cards by shared words rather than by meaning.
- Categories named by the researcher can bias the results. Let participants name their own groups.
- A similarity matrix hides why people grouped items. Read comments alongside the numbers.
- Choosing a cut height without checking the result can produce groups that no participant would recognize.
Exercise
A pair of cards is grouped together by 2 of 8 participants. What is their similarity, and what is their distance?
Show answer
The similarity is 2 / 8 = 0.25, or 25%. The distance is 1 - 0.25 = 0.75.