Dot Product and Vector Similarity
What you'll learn: How to measure how "aligned" two vectors are using a simple mathematical operation that underpins similarity in ML.
The Core Idea
The dot product takes two vectors of the same length and produces a single number (a scalar). It tells you how much the vectors point in the same direction.
Formula: For two vectors a = [a₁, a₂, a₃] and b = [b₁, b₂, b₃]:
a · b = a₁×b₁ + a₂×b₂ + a₃×b₃
You multiply corresponding elements and sum them up.
Geometric Interpretation
The dot product measures alignment:
- Large positive value: Vectors point in similar directions (similar)
- Zero: Vectors are perpendicular (unrelated)
- Large negative value: Vectors point in opposite directions (dissimilar)
Real-World Analogy
Imagine two shoppers rating products on a scale. Shopper A rates [5, 4, 1] for three items, Shopper B rates [5, 3, 2].
Dot product: 5×5 + 4×3 + 1×2 = 25 + 12 + 2 = 39
This large positive number suggests they have similar tastes! If Shopper C rated [1, 2, 5] (opposite preferences), their dot product with A would be much smaller: 5×1 + 4×2 + 1×5 = 18 — less similar.
Why This Matters in ML
Machine learning constantly asks "how similar are these things?" Whether comparing:
- User preferences (recommendation systems)
- Word meanings (natural language processing)
- Image features (computer vision)
The dot product gives a quick similarity score using just vector operations you already know: scalar multiplication and addition.
Key Takeaway: The dot product multiplies corresponding vector elements and sums them, producing a scalar that measures how aligned (similar) two vectors are — the foundation of similarity calculations in machine learning.