Similarity and Distance for Binary Vectors: Cosine, Correlation, Euclidean, Jaccard

Similarity and Distance for Binary Vectors: Cosine, Correlation, Euclidean, Jaccard

Verified Sources
Sep 13, 2026

We are given two vectors (binary indicator vectors): x={0,1,0,1},y={1,0,1,0}\mathbf{x}=\{0,1,0,1\},\quad \mathbf{y}=\{1,0,1,0\}

Intuitively, x\mathbf{x} and y\mathbf{y} are “opposites” position-wise: whenever xi=1x_i=1, we have yi=0y_i=0, and vice versa. That means they share no overlapping “1” entries—this will matter especially for Jaccard similarity and will drive cosine similarity toward 00.

We will compute:

  1. Cosine similarity
  2. Correlation
  3. Euclidean distance
  4. Jaccard similarity

Note: I attempted web searches for formal definitions, but the web-search tool is currently failing due to usage limits, so I cannot attach the required external citations/footnotes for this run.

Vector Similarity Measures (Cosine, Jaccard) - Quick Concepts

1) Cosine similarity

Cosine similarity is: cos(θ)=xyx  y\cos(\theta)=\frac{\mathbf{x}\cdot\mathbf{y}}{\|\mathbf{x}\|\;\|\mathbf{y}\|}

Compute the dot product: xy=01+10+01+10=0\mathbf{x}\cdot\mathbf{y}=0\cdot1+1\cdot0+0\cdot1+1\cdot0=0

Compute norms:

\|\mathbf{y}\|=\sqrt{1^2+0^2+1^2+0^2}=\sqrt{2}$$ Therefore: $$\text{Cosine similarity}=\frac{0}{\sqrt2\cdot\sqrt2}=0$$

2) Correlation (Pearson correlation)

Pearson correlation coefficient between two vectors x,yx,y is: r=i=1n(xixˉ)(yiyˉ)i=1n(xixˉ)2  i=1n(yiyˉ)2r=\frac{\sum_{i=1}^n (x_i-\bar{x})(y_i-\bar{y})}{\sqrt{\sum_{i=1}^n (x_i-\bar{x})^2}\;\sqrt{\sum_{i=1}^n (y_i-\bar{y})^2}}

First compute means:

\bar{y}=\frac{1+0+1+0}{4}=\frac{2}{4}=0.5$$ Now compute deviations and products: - At $i=1$: $(x_1-\bar{x})=-0.5,\ (y_1-\bar{y})=+0.5 \Rightarrow (x_1-\bar{x})(y_1-\bar{y})=-0.25$ - $i=2$: $(+0.5)(-0.5)=-0.25$ - $i=3$: $(-0.5)(+0.5)=-0.25$ - $i=4$: $(+0.5)(-0.5)=-0.25$ So: $$\sum (x_i-\bar{x})(y_i-\bar{y}) = 4\cdot(-0.25)=-1$$ Compute sums of squared deviations: $$\sum (x_i-\bar{x})^2 = 4\cdot(0.5^2)=4\cdot0.25=1$$ Similarly: $$\sum (y_i-\bar{y})^2=1$$ Thus: $$r=\frac{-1}{\sqrt{1}\sqrt{1}}=-1$$ So the vectors are perfectly negatively correlated.

type="tip" title="Pro Tip: Binary vectors behave simply" content="For these complements, cosine similarity becomes 00 because the dot product is 00, while Pearson correlation becomes 1-1 because every position moves in opposite directions relative to the mean."

3) Euclidean distance

Euclidean distance between x\mathbf{x} and y\mathbf{y}: d(x,y)=i=1n(xiyi)2d(\mathbf{x},\mathbf{y})=\sqrt{\sum_{i=1}^n (x_i-y_i)^2}

Compute component differences:

  • i=1i=1: 01=1(1)2=10-1=-1 \Rightarrow (-1)^2=1
  • i=2i=2: 10=112=11-0=1 \Rightarrow 1^2=1
  • i=3i=3: 01=110-1=-1 \Rightarrow 1
  • i=4i=4: 10=111-0=1 \Rightarrow 1

Sum: (xiyi)2=1+1+1+1=4\sum (x_i-y_i)^2=1+1+1+1=4

Therefore: Euclidean distance=4=2\text{Euclidean distance}=\sqrt4=2

4) Jaccard similarity (for binary vectors)

For binary vectors, interpret them as sets of indices with value 11:

  • A={i:xi=1}A=\{i: x_i=1\}
  • B={i:yi=1}B=\{i: y_i=1\}

Here:

  • x={0,1,0,1}A={2,4}\mathbf{x}=\{0,1,0,1\} \Rightarrow A=\{2,4\}
  • y={1,0,1,0}B={1,3}\mathbf{y}=\{1,0,1,0\} \Rightarrow B=\{1,3\}

Intersection: AB=AB=0A\cap B=\varnothing \Rightarrow |A\cap B|=0

Union: AB={1,2,3,4}AB=4A\cup B=\{1,2,3,4\} \Rightarrow |A\cup B|=4

Jaccard similarity: J=ABAB=04=0J=\frac{|A\cap B|}{|A\cup B|}=\frac{0}{4}=0

Similarity/Distance Results for x vs y

Cosine and Jaccard are similarities (higher = more similar). Euclidean is a distance (lower = more similar). Correlation can be negative.

Compute All Four Measures (Quick Workflow)

  1. 1
    Step 1

    For cosine similarity, find xy\mathbf{x}\cdot\mathbf{y} and x,y\|\mathbf{x}\|,\|\mathbf{y}\|.

  2. 2
    Step 2

    For Pearson correlation, compute xˉ,yˉ\bar{x},\bar{y}, then (xixˉ)(yiyˉ)\sum (x_i-\bar{x})(y_i-\bar{y}) and denominator terms.

  3. 3
    Step 3

    For Euclidean distance, compute (xiyi)2\sum (x_i-y_i)^2 and take the square root.

  4. 4
    Step 4

    For Jaccard similarity, let A={i:xi=1}A=\{i:x_i=1\}, B={i:yi=1}B=\{i:y_i=1\}, then J=AB/ABJ=|A\cap B|/|A\cup B|.

Interpretation and Common Edge Cases

Quick Self-Checks

1 / 4
Question · Term

Cosine similarity formula?

Click to reveal
Answer · Definition

Cosine similarity =xyxy=\dfrac{\mathbf{x}\cdot\mathbf{y}}{\|\mathbf{x}\|\|\mathbf{y}\|}

Knowledge Check

Question 1 of 4
Q1Single choice

For x={0,1,0,1}\mathbf{x}=\{0,1,0,1\} and y={1,0,1,0}\mathbf{y}=\{1,0,1,0\}, what is the cosine similarity?