Skip to content
BI & Data ScienceClustering: finding groups without labels

Formulas for this chapter

Euclidean distance

D(X1, X2) = sqrt( (x11 - x21)^2 + (x12 - x22)^2 + ... + (x1n - x2n)^2 ) For assignment, compare the squared value and skip the root.

Any continuous-scale similarity: k-means assignment, KNN, load-distance. Standardise the columns first or the widest one decides the answer.

x1j, x2j
Value of variable j for observations 1 and 2
n
Number of variables

Standardising a column

z = (x - mean) / standard deviation (z-score) or x' = (x - min) / (max - min) (min-max, range 0 to 1)

Before any distance-based method. z-scoring in Excel is =(x - AVERAGE(col)) / STDEV.S(col); in R it is scale(data).

mean, standard deviation
Computed down the column, not across the row
min, max
Smallest and largest values in the column

Centroid and WCSS

centroid_j = mean of variable j over the cluster's members WCSS = SUM over clusters SUM over members ( distance to own centroid )^2

The update step of k-means, and the elbow plot. WCSS falls monotonically in k and is zero at k = n, so read the bend rather than minimising it.

centroid_j
The cluster's mean on variable j
k
Number of clusters, fixed before k-means runs
Step 1 of 26
The ideaTheory

Twenty wines on a table

Twenty bottles, and for each one two numbers: alcohol content and alkalinity of ash. Nobody has told you which wines belong together.

Plot them and your eye does the work in a second. There are three clumps: low alcohol and low alkalinity, middling both, and high both.

Clustering is the arithmetic that finds those clumps when there are six variables instead of two and no picture is possible. Nothing is being predicted, because nothing was labelled.