Cosine Similarity

Fundamentals of AI/ML · Prof. Parikshit Pareek & Prof. Jitin Singla · IIT Roorkee
P-squared Lab logo
Integral Lab logo

The inner product factorises as xy = ‖x2y2 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 θ  =  xy / (‖x2 · ‖y2)   ∈   [−1, 1]
━━ vector x   ━━ vector y

Live values

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

Quick presets

Interpretation

Where this appears in ML