Back to the 2022 paper

Module 2: Data Mining and Association Rule Mining

20227m

For the following vectors, x\mathbf{x} and y\mathbf{y}, calculate the indicated similarity or distance measures :

(i) x=(0,1,0,1)\mathbf{x} = (0, -1, 0, 1), y=(1,0,1,0)\mathbf{y} = (1, 0, -1, 0) cosine, correlation
(ii) x=(0,1,0,1)\mathbf{x} = (0, 1, 0, 1), y=(1,0,1,0)\mathbf{y} = (1, 0, 1, 0) Euclidean, SMC

Worked SolutionAI Assisted

Similarity/Distance Measures — Two Vector Pairs

(i) x = (0, -1, 0, 1), y = (1, 0, -1, 0) — Cosine & Correlation

Cosine similarity:
cos(x,y)=xyxy\cos(\mathbf{x},\mathbf{y}) = \frac{\mathbf{x}\cdot\mathbf{y}}{\|\mathbf{x}\|\|\mathbf{y}\|}

  • Dot product: (0)(1)+(1)(0)+(0)(1)+(1)(0)=0(0)(1)+(-1)(0)+(0)(-1)+(1)(0) = 0
  • x=02+(1)2+02+12=2\|\mathbf{x}\| = \sqrt{0^2+(-1)^2+0^2+1^2} = \sqrt{2}
  • y=12+02+(1)2+02=2\|\mathbf{y}\| = \sqrt{1^2+0^2+(-1)^2+0^2} = \sqrt{2}

cos(x,y)=022=0\cos(\mathbf{x},\mathbf{y}) = \frac{0}{\sqrt{2}\cdot\sqrt{2}} = \boxed{0}

Correlation:
Mean xˉ=01+0+14=0\bar{x} = \dfrac{0-1+0+1}{4} = 0, mean yˉ=1+01+04=0\bar{y} = \dfrac{1+0-1+0}{4} = 0

Since both means are already 0, (xixˉ)=xi(x_i-\bar{x}) = x_i and (yiyˉ)=yi(y_i-\bar{y})=y_i:

r=xiyixi2yi2=02×2=0r = \frac{\sum x_i y_i}{\sqrt{\sum x_i^2 \cdot \sum y_i^2}} = \frac{0}{\sqrt{2 \times 2}} = \boxed{0}

Both cosine and correlation are 0 — x and y are orthogonal/uncorrelated.


(ii) x = (0, 1, 0, 1), y = (1, 0, 1, 0) — Euclidean & SMC

Euclidean distance:
d(x,y)=(01)2+(10)2+(01)2+(10)2=1+1+1+1=4=2d(\mathbf{x},\mathbf{y}) = \sqrt{(0-1)^2+(1-0)^2+(0-1)^2+(1-0)^2} = \sqrt{1+1+1+1} = \sqrt{4} = \boxed{2}

Simple Matching Coefficient (SMC) — counts matches including 0-0 (used for symmetric binary attributes):
SMC=f11+f00f11+f00+f01+f10SMC = \frac{f_{11}+f_{00}}{f_{11}+f_{00}+f_{01}+f_{10}}

Position x y Match type
1 0 1 f01
2 1 0 f10
3 0 1 f01
4 1 0 f10

f11=0, f00=0, f01=2, f10=2f_{11}=0,\ f_{00}=0,\ f_{01}=2,\ f_{10}=2

SMC=0+00+0+2+2=0SMC = \frac{0+0}{0+0+2+2} = \boxed{0}

Summary Table

Pair Measure Value Interpretation
x,y (set i) Cosine 0 Orthogonal (no directional similarity)
x,y (set i) Correlation 0 No linear relationship
x,y (set ii) Euclidean distance 2 Maximum distance for these binary 4-D vectors
x,y (set ii) SMC 0 Zero matching bits (complete complements) — no 0-0 or 1-1 overlap

Both vector pairs turn out to be complete "opposites" of each other bit-wise, which is why every measure returns either 0 (no similarity/correlation) or the maximum possible distance.

Similar questions