Cluster Analysis · Data Mining

Types of Data in Cluster Analysis

Watch lectures

Types of Data in Cluster Analysis

Clustering algorithms depend on how similarity between objects is measured, which in turn depends on the type of data. This topic defines proximity measures for every data type, plus the key issue of standardising heterogeneous attributes.

1. Interval-Scaled (Numeric) Variables

Continuous measurements (xifx_{if} = value of object ii on attribute ff).

Step 1 — Normalise to remove scale effects (so currency/km/age are comparable) using the z-score:

xif′=xif−mfsf,mf=1n∑i=1nxif,sf=1n∑i=1n(xif−mf)2x'_{if}=\frac{x_{if}-m_f}{s_f},\qquad m_f=\frac{1}{n}\sum_{i=1}^{n}x_{if},\qquad s_f=\sqrt{\frac{1}{n}\sum_{i=1}^{n}(x_{if}-m_f)^2}

Step 2 — Distance measures between objects ii and jj:

Euclidean distance (L2L_2):

d(i,j)=(xi1−xj1)2+(xi2−xj2)2+⋯+(xip−xjp)2d(i,j)=\sqrt{(x_{i1}-x_{j1})^2+(x_{i2}-x_{j2})^2+\dots+(x_{ip}-x_{jp})^2}

Manhattan / city-block distance (L1L_1): d(i,j)=∑f=1p∣xif−xjf∣d(i,j)=\sum_{f=1}^{p}|x_{if}-x_{jf}|

Minkowski distance (general LqL_q): d(i,j)=(∑f=1p∣xif−xjf∣q)1/qd(i,j)=\left(\sum_{f=1}^{p}|x_{if}-x_{jf}|^{q}\right)^{1/q}

Chebyshev / supremum (L∞L_\infty): d(i,j)=max⁡f∣xif−xjf∣d(i,j)=\max_f |x_{if}-x_{jf}|

Weighted Euclidean (attribute weighting): d(i,j)=∑fwf(xif−xjf)2d(i,j)=\sqrt{\sum_f w_f (x_{if}-x_{jf})^2}

Note: L∞L_\infty is the limit of Minkowski as q→∞q \to \infty; larger qq gives more weight to the largest difference.

Numerical example — A=(1,2)A=(1,2), B=(4,6)B=(4,6):

dL1=∣1−4∣+∣2−6∣=7,dL2=9+16=5,dL∞=max⁡(3,4)=4d_{L_1}=|1-4|+|2-6|=7,\qquad d_{L_2}=\sqrt{9+16}=5,\qquad d_{L_\infty}=\max(3,4)=4
LqL_q 1 2 3 ∞\infty
distance 7 5 4.497 4

Similarity from distance: s(i,j)=11+d(i,j)s(i,j)=\dfrac{1}{1+d(i,j)}, or use cosine similarity

cos⁡(i,j)=x⃗i⋅x⃗j∥x⃗i∥ ∥x⃗j∥=∑fxifxjf∑fxif2∑fxjf2\cos(i,j)=\frac{\vec x_i\cdot \vec x_j}{\|\vec x_i\|\,\|\vec x_j\|}=\frac{\sum_f x_{if}x_{jf}}{\sqrt{\sum_f x_{if}^2}\sqrt{\sum_f x_{jf}^2}}

Cosine is preferred for text/document vectors because it ignores magnitude.

2. Binary Variables

Symmetric binary (both outcomes equally important, e.g. gender):

d(i,j)=r+sq+r+s+td(i,j)=\frac{r+s}{q+r+s+t}

Asymmetric binary (one outcome rarer/more meaningful — "1" usually means presence):

d(i,j)=r+sq+r+s(Jaccard distance)d(i,j)=\frac{r+s}{q+r+s}\qquad(\text{Jaccard distance})

where qq = both 1, rr = ii=1 & jj=0, ss = ii=0 & jj=1, tt = both 0.

Jaccard similarity =qq+r+s=\dfrac{q}{q+r+s}; better than overall similarity q+tq+r+s+t\dfrac{q+t}{q+r+s+t} when 0s dominate (sparse data).

Numerical example (name, gender, fever, cough, test-1..4 from the classic table; asymmetric attributes: fever, cough, t1-t4):

Pair q r s Symmetric dist Jaccard dist
Jack–Mary 2 1 2 (1+2)/6 = 0.50 3/5 = 0.60
Jack–Jim 1 2 1 3/6 = 0.50 3/4 = 0.75
Jim–Mary 1 1 2 2/6 = 0.33 2/4 = 0.50

3. Nominal (Categorical) Variables

Values from an unordered set with MM states. Simple matching:

d(i,j)=p−mp(m = number of matches, p = number of attributes)d(i,j)=\frac{p-m}{p}\qquad \text{($m$ = number of matches, $p$ = number of attributes)}

Alternative: convert to MM asymmetric binary attributes (one-hot) and use Jaccard.

Example: (red, medium, A) vs (blue, medium, B) → p=3p=3, m=1m=1 → d=2/3=0.67d = 2/3 = 0.67.

4. Ordinal Variables

An ordinal value can be ranked but not metrically compared (e.g. small < medium < large, ranks 1..MM).

  1. Replace each value by its rank rif∈{1..Mf}r_{if} \in \{1..M_f\}.
  2. Map the rank to [0,1]:
zif=rif−1Mf−1z_{if}=\frac{r_{if}-1}{M_f-1}
  1. Use any interval-scaled distance (e.g. Euclidean) on the transformed values.

Example: {fair, good, excellent} mapped to {0,0.5,1}\{0, 0.5, 1\} → good vs excellent: z=0.5z=0.5 vs 11.

5. Ratio-Scaled Variables

Positive measurements on a non-linear scale (exponential growth/decay: bacterial population, radioactive decay). Apply a log transform first, then treat as interval-scaled:

yif=log⁡(xif)oryif=log⁡10(xif)y_{if}=\log(x_{if})\quad\text{or}\quad y_{if}=\log_{10}(x_{if})

6. Mixed Types of Variables

One distance that handles all types together. For attributes f=1…pf = 1 \dots p, with indicator δij(f)=0\delta_{ij}^{(f)}=0 if xifx_{if} or xjfx_{jf} is missing or when ff is asymmetric binary with both values 0, otherwise 1:

d(i,j)=∑f=1pδij(f) dij(f)∑f=1pδij(f)d(i,j)=\frac{\sum_{f=1}^{p}\delta_{ij}^{(f)}\,d_{ij}^{(f)}}{\sum_{f=1}^{p}\delta_{ij}^{(f)}}

Per-attribute contribution:

Type dij(f)d_{ij}^{(f)}
Interval-scaled ∣xif−xjf∣max⁡hxhf−min⁡hxhf\dfrac{|x_{if}-x_{jf}|}{\max_h x_{hf}-\min_h x_{hf}}
Nominal 0 if equal, 1 otherwise
Ordinal ∣rif−rjf∣Mf−1\dfrac{|r_{if}-r_{jf}|}{M_f-1}
Ratio-scaled distance on log⁡\log values, range-normalised
Binary 0/1 (Jaccard style)

Worked mixed example (test-1: nominal; test-2: ordinal with M=3M=3; test-3: ratio 1.5×1031.5\times10^3 etc.)

Object test-1 test-2 test-3
A code-A excellent 1.5e3
B code-B fair 2.5e4
C code-C good 1.3e5
  • test-1 (nominal) contributes 1 for every pair (all different).
  • test-2 (ordinal, M=3M=3): excellent = 1, fair = 0, good = 0.5 → dAB=1d_{AB}=1, dAC=0.5d_{AC}=0.5, dBC=0.5d_{BC}=0.5.
  • test-3 (ratio, log10_{10} = 3.18, 4.40, 5.11; range 1.93): dAB=0.63d_{AB}=0.63, dAC=1.0d_{AC}=1.0, dBC=0.37d_{BC}=0.37.
d(A,B)=1+1+0.633=0.88,d(A,C)=1+0.5+13=0.83,d(B,C)=1+0.5+0.373=0.62d(A,B)=\frac{1+1+0.63}{3}=0.88,\quad d(A,C)=\frac{1+0.5+1}{3}=0.83,\quad d(B,C)=\frac{1+0.5+0.37}{3}=0.62

7. Why the Data Type Matters

Data type Typical measure Watch out for
Interval Euclidean / Manhattan / cosine Scale differences → normalise
Binary asymmetric Jaccard Dominance of 0s
Nominal Simple matching / one-hot + Jaccard High dimensionality after one-hot
Ordinal Rank-normalised Euclidean Assume monotone spacing
Ratio Log-transform + interval Zero/negative values
Mixed Weighted general distance with δ\delta Missing values, attribute weighting

8. Exam Points

  • Explain proximity measures for interval, binary, nominal, ordinal and ratio variables — 10 marks (very frequent).
  • Compute Euclidean, Manhattan, Minkowski and supremum distances for two points — 3-5 marks numerical.
  • Compute Jaccard/simple matching distance from a table of binary attributes — 5 marks numerical.
  • Explain the mixed-type distance formula with δij(f)\delta_{ij}^{(f)} — 5-7 marks.
  • Why is normalisation needed before clustering? — 3 marks.
Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.

← All Data Mining modules