Distance metrics

L-p metrics

Manhattan distance (L1)

Given two vectors pp and qq, such that

 0 

we define the Manhattan distance as:

 1 

Euclidean distance (L2)

In general, for points given by Cartesian coordinates in nn-dimensional Euclidean space, the distance is

 2 

Cluster distances

Within-cluster sum of squares (WCSS)

Given a set of observations (x1,x2,…,xnx_1, x_2,\dots,x_n), where each observation is a dd-dimensional real vector, kk-means clustering aims to partition the nn observations into kk (≤n\leq n) sets S={S1,S2,…,Sk}S=\lbrace S_1, S_2, \dots, S_k\rbrace so as to minimize the within-cluster sum of squares (WCSS) (i.e. variance). Formally, the objective is to find:

 3 

where μi\mu_i is the mean of points in SiS_i. This is equivalent to minimizing the pairwise squared deviations of points in the same cluster:

 4 

The equivalence can be deduced from identity

 5 

Because the total variance is constant, this is equivalent to maximizing the sum of squared deviations between points in different clusters (between-cluster sum of squares, BCSS) which follows from the law of total variance.

Dunn index

A full explanation is available at Dunn index.

Gower distance

A full explanation with examples is available at Gower distance.