Back to the 2021 paper

Module 2: Data Mining and Association Rule Mining

20214m

For the following vectors, x and y, calculate the indicated similarity or distance measures :

x={0,1,0,1},y={1,0,1,0}\mathbf{x} = \{0, 1, 0, 1\}, \quad \mathbf{y} = \{1, 0, 1, 0\}

Calculate:

  1. Cosine similarity
  2. Correlation
  3. Euclidean distance
  4. Jaccard similarity
Worked SolutionAI Assisted

Similarity/Distance Measures for x = {0,1,0,1}, y = {1,0,1,0}

Setup

x=(0,1,0,1),y=(1,0,1,0)\mathbf{x} = (0, 1, 0, 1), \quad \mathbf{y} = (1, 0, 1, 0)

1. 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+12+02+12=2\|\mathbf{x}\| = \sqrt{0^2+1^2+0^2+1^2} = \sqrt{2}
  • y=12+02+12+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}

2. Correlation

Mean: xˉ=yˉ=0.5\bar{x} = \bar{y} = 0.5

i xixˉx_i-\bar{x} yiyˉy_i-\bar{y} product (xixˉ)2(x_i-\bar{x})^2 (yiyˉ)2(y_i-\bar{y})^2
1 -0.5 0.5 -0.25 0.25 0.25
2 0.5 -0.5 -0.25 0.25 0.25
3 -0.5 0.5 -0.25 0.25 0.25
4 0.5 -0.5 -0.25 0.25 0.25
Σ -1.0 1.0 1.0

r=1.01.0×1.0=1r = \frac{-1.0}{\sqrt{1.0 \times 1.0}} = \boxed{-1}
(makes sense: y is exactly the complement of x, so they're perfectly negatively correlated)

3. 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}

4. Jaccard Similarity

Binary co-occurrence counts across the 4 positions:

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

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

J(x,y)=f11f01+f10+f11=02+2+0=0J(\mathbf{x},\mathbf{y}) = \frac{f_{11}}{f_{01}+f_{10}+f_{11}} = \frac{0}{2+2+0} = \boxed{0}

Summary

Measure Value Interpretation
Cosine similarity 0 Vectors are orthogonal
Correlation -1 Perfectly negatively correlated
Euclidean distance 2 Maximum possible distance for these binary vectors
Jaccard similarity 0 No 1-1 overlap at all — completely dissimilar on "presence"

All four measures agree that x and y are maximally dissimilar — they're exact bitwise complements of each other.

Similar questions