Skip to main content

Section 3.4 Application in Data Science: Measuring Similarity in Tastes

Every time a streaming service tells you “because you watched Sinners…”, some piece of software has decided that your taste resembles the taste of other people in its database. Deciding whose taste resembles whose can be framed as a geometry problem, and one tool that can help us decide is the dot product.
The first step is to turn taste into a vector. Fix a list of movies and ask each person to rate every one of them on a scale from \(-5\) to \(5\text{,}\) where \(5\) means “loved it”, \(-5\) means “I want those two hours back”, and \(0\) means indifference. Reading the ratings off in the same order for everybody turns each person into a vector, and the question “do these two people have similar taste?” becomes a question about the angle between two vectors, which by Theorem 3.3 is exactly what the dot product measures.

Definition 3.25 Angular Distance and Cosine Similarity.

Let \(\mathbf u\) and \(\mathbf v\) be two nonzero vectors. Their angular distance is the angle \(\theta\) between them, obtained from (3.4),
\begin{equation} d_A(\mathbf u,\mathbf v) = \theta = \cos^{-1}\left(\frac{\mathbf u \cdot \mathbf v}{\|\mathbf u\|\|\mathbf v\|}\right).\tag{3.12} \end{equation}
The quantity \(\dfrac{\mathbf u \cdot \mathbf v}{\|\mathbf u\|\|\mathbf v\|} = \cos\theta\) appearing inside is called the cosine similarity of \(\mathbf u\) and \(\mathbf v\text{.}\) The smaller the angular distance, the more similar the two vectors.
Angular distance asks “how nearly do these two vectors point the same way?” Notice that it is completely blind to the lengths of \(\mathbf u\) and \(\mathbf v\text{:}\) multiplying either vector by a positive number leaves \(\theta\) untouched. We will come back to what that means for moviegoers.

Two Movies at a Time.

Two movies give vectors in \(\mathbb R^2\text{,}\) which we can draw. Take two of the ten films nominated for Best Picture at the 2026 Academy Awards, Sinners and Hamnet, and record each person’s rating of Sinners as the first component and of Hamnet as the second. Mehdi, Norm, and Popcorn rate them as follows:
\begin{equation*} \begin{aligned} \text{Mehdi:} \quad \mathbf u \amp = \langle 4, 5\rangle \\ \text{Norm:} \quad \mathbf v \amp = \langle 5, 3\rangle \\ \text{Popcorn:} \quad \mathbf w \amp = \langle -4, -2\rangle. \end{aligned} \end{equation*}
Mehdi and Norm both enjoyed the two films; Popcorn sat through both of them and regretted it. Figure 3.26 shows the three taste vectors.
Diagram Exploration Keyboard Controls
Key Action
Enter, A Activate keyboard driven exploration
B Activate menu driven exploration
Escape Leave exploration mode
Cursor down Explore next lower level
Cursor up Explore next upper level
Cursor right Explore next element on level
Cursor left Explore previous element on level
X Toggle expert mode
W Extra details if available
Space Repeat speech
M Activate step magnification
Comma Activate direct magnification
N Deactivate magnification
Z Toggle subtitles
C Cycle contrast settings
T Monochrome colours
L Toggle language (if available)
K Kill current sound
Y Stop sound output
O Start and stop sonification
P Repeat sonification output
Figure 3.26. The taste vectors \(\mathbf u\) (Mehdi), \(\mathbf v\) (Norm), and \(\mathbf w\) (Popcorn). The angle \(\theta\) is the angular distance between \(\mathbf u\) and \(\mathbf v\text{.}\)

Example 3.27 Who should watch a movie together?

Using the taste vectors above, rank the three pairs by angular distance.
Solution.
The three dot products are
\begin{equation*} \begin{aligned} \mathbf u \cdot \mathbf v \amp = 20 + 15 = 35, \\ \mathbf u \cdot \mathbf w \amp = -16 - 10 = -26, \\ \mathbf v \cdot \mathbf w \amp = -20 - 6 = -26, \end{aligned} \end{equation*}
and the lengths are \(\|\mathbf u\| = \sqrt{41}\text{,}\) \(\|\mathbf v\| = \sqrt{34}\text{,}\) and \(\|\mathbf w\| = \sqrt{20}\text{.}\) Then, by (3.12),
\begin{equation*} \begin{aligned} \text{Mehdi, Norm:} \quad \cos\theta \amp = \frac{35}{\sqrt{41}\,\sqrt{34}} \approx 0.9374 \\[2pt] \text{Mehdi, Popcorn:} \quad \cos\theta \amp = \frac{-26}{\sqrt{41}\,\sqrt{20}} \approx -0.9080 \\[2pt] \text{Norm, Popcorn:} \quad \cos\theta \amp = \frac{-26}{\sqrt{34}\,\sqrt{20}} \approx -0.9971. \end{aligned} \end{equation*}
Taking \(\cos^{-1}\) of each of these gives the three angular distances.
Table 3.28. Angular distance between the three taste vectors.
Pair \(\cos\theta\) \(d_A\)
Mehdi, Norm \(0.9374\) \(20.4^\circ\)
Mehdi, Popcorn \(-0.9080\) \(155.2^\circ\)
Norm, Popcorn \(-0.9971\) \(175.6^\circ\)
Mehdi and Norm are the movie buddies. The sign of the dot product already told us most of the story: \(\mathbf u \cdot \mathbf v > 0\) means an acute angle and broadly shared taste, while \(\mathbf v \cdot \mathbf w < 0\) means an obtuse angle, and here an angle of nearly \(180^\circ\) — Norm and Popcorn are as close to being opposites as two moviegoers can be.

Angular Distance Ignores Enthusiasm.

Suppose Ray, Vera, and Gus rate the same two films
\begin{equation*} \begin{aligned} \text{Ray:} \quad \mathbf a \amp = \langle 2, 2\rangle \\ \text{Vera:} \quad \mathbf b \amp = \langle 5, 4\rangle \\ \text{Gus:} \quad \mathbf c \amp = \langle 5, 5\rangle, \end{aligned} \end{equation*}
as in Figure 3.29. Since \(\mathbf c = \tfrac52\mathbf a\text{,}\) the vectors \(\mathbf a\) and \(\mathbf c\) point in exactly the same direction, so \(d_A(\mathbf a,\mathbf c) = 0^\circ\text{:}\) as far as angular distance is concerned, Ray and Gus have identical taste. Vera sits about \(6.3^\circ\) away from that shared direction, since
\begin{equation*} \cos\theta = \frac{\mathbf b \cdot \mathbf c}{\|\mathbf b\|\|\mathbf c\|} = \frac{25+20}{\sqrt{41}\,\sqrt{50}} \approx 0.9939. \end{equation*}
Diagram Exploration Keyboard Controls
Key Action
Enter, A Activate keyboard driven exploration
B Activate menu driven exploration
Escape Leave exploration mode
Cursor down Explore next lower level
Cursor up Explore next upper level
Cursor right Explore next element on level
Cursor left Explore previous element on level
X Toggle expert mode
W Extra details if available
Space Repeat speech
M Activate step magnification
Comma Activate direct magnification
N Deactivate magnification
Z Toggle subtitles
C Cycle contrast settings
T Monochrome colours
L Toggle language (if available)
K Kill current sound
Y Stop sound output
O Start and stop sonification
P Repeat sonification output
Figure 3.29. Ray, Vera, and Gus. Ray’s vector \(\mathbf a\) lies along Gus’s vector \(\mathbf c\text{,}\) so their angular distance is \(0\text{,}\) even though Gus handed out far more generous ratings.
This is the scale invariance noted after Definition 3.25, seen from the moviegoers’ side. Ray is a cautious rater and Gus is an enthusiastic one, but they ranked the two films the same way and in the same proportion, and angular distance sees only that shared direction. If you regard a lukewarm reviewer and a euphoric one who agree about every film as having the same taste, this is exactly the behavior you want.

More Movies, More Dimensions.

Nothing above depended on there being exactly two movies. With \(n\) movies, a person’s taste vector is \(\mathbf u = \langle u_1, u_2, \ldots, u_n\rangle\) in \(\mathbb R^n\text{,}\) the dot product of (3.5) becomes a sum of \(n\) products, \(\mathbf u \cdot \mathbf v = \sum_{i=1}^{n} u_i v_i\text{,}\) and the length of a vector becomes \(\|\mathbf u\| = \sqrt{\sum_{i=1}^{n} u_i^2}\text{.}\) The angular distance of Definition 3.25 carries over verbatim:
\begin{equation} d_A(\mathbf u,\mathbf v) = \cos^{-1}\left( \frac{\sum_{i=1}^{n} u_i v_i} {\sqrt{\sum_{i=1}^{n} u_i^2}\,\sqrt{\sum_{i=1}^{n} v_i^2}}\right).\tag{3.13} \end{equation}
We can no longer draw the picture, but every formula still applies, and the language of Remark 3.6 still means something: two taste vectors with \(\mathbf u \cdot \mathbf v = 0\) are orthogonal, an angular distance of \(90^\circ\text{,}\) which here says that knowing one person’s ratings tells you nothing about the other’s. This is what makes the dot product useful in practice. A streaming service with \(50{,}000\) titles works in \(\mathbb R^{50{,}000}\text{,}\) and finding the users nearest to you is still nothing more than the arithmetic in (3.13).

Example 3.30 All ten nominees.

List the ten 2026 Best Picture nominees alphabetically—Bugonia, F1, Frankenstein, Hamnet, Marty Supreme, One Battle After Another, The Secret Agent, Sentimental Value, Sinners, Train Dreams—and suppose Mehdi, Norm, and Popcorn rate all ten:
\begin{equation*} \begin{aligned} \mathbf u \amp = \langle 3,\,-1,\,2,\,5,\,0,\,5,\,4,\,3,\,4,\,2\rangle \\ \mathbf v \amp = \langle 1,\,4,\,3,\,3,\,5,\,4,\,0,\,1,\,5,\,-2\rangle \\ \mathbf w \amp = \langle -2,\,3,\,-3,\,-2,\,4,\,-1,\,-4,\,-5,\,-4,\,-3\rangle. \end{aligned} \end{equation*}
(The fourth and ninth entries are the Hamnet and Sinners ratings from before.) Which pair has the most similar taste?
Solution.
The dot products are \(\mathbf u \cdot \mathbf v = 59\text{,}\) \(\mathbf u \cdot \mathbf w = -83\text{,}\) and \(\mathbf v \cdot \mathbf w = -8\text{,}\) and the lengths are \(\|\mathbf u\| = \sqrt{109}\text{,}\) \(\|\mathbf v\| = \sqrt{106}\text{,}\) and \(\|\mathbf w\| = \sqrt{109}\text{.}\) Applying (3.13) to each pair gives the following.
Table 3.31. Angular distance across all ten nominees.
Pair \(\cos\theta\) \(d_A\)
Mehdi, Norm \(0.549\) \(56.7^\circ\)
Mehdi, Popcorn \(-0.762\) \(139.6^\circ\)
Norm, Popcorn \(-0.074\) \(94.3^\circ\)
Mehdi and Norm are again the closest pair, though the extra eight films have pulled them apart: their angular distance grew from \(20.4^\circ\) to \(56.7^\circ\) once we stopped judging them on Sinners and Hamnet alone. Norm and Popcorn are nearly orthogonal, with an angle of \(94.3^\circ\text{;}\) their tastes are essentially unrelated rather than opposed, which is precisely the distinction the two-movie picture was too small to make.
Ten components are a lot to handle by hand, and a real recommender system deals with thousands. The cell below carries out the computation of Example 3.30. Press Evaluate to run it, then edit the ratings and run it again to see whose taste your own vector is closest to.
You have attempted of activities on this page.