Cosine Similarity

EEC 351 · Fundamentals of AI/ML · Prof. Parikshit Pareek & Prof. Jitin Singla · IIT Roorkee

The inner product factorises as x⊤y = ‖x‖2 ‖y‖2 cos θ. Solving for cos θ gives the cosine similarity — a number in [−1, 1] that measures how much two vectors point in the same direction, ignoring their lengths. Drag either arrowhead to change the vectors.

cos θ  =  x⊤y / (‖x‖2 · ‖y‖2)   ∈   [−1, 1]
━━ vector x   ━━ vector y

Live values

x = (—)   ‖x‖2 = —
y = (—)   ‖y‖2 = —
x⊤y = —
θ = —
cos θ = —
−1 (opposite)0 (orthogonal)+1 (aligned)

Quick presets

Interpretation

Where this appears in ML