Grokking Algorithms



Yüklə 348,95 Kb.
Pdf görüntüsü
səhifə95/122
tarix05.12.2023
ölçüsü348,95 Kb.
#173611
1   ...   91   92   93   94   95   96   97   98   ...   122
grokking-algorithms-illustrated-programmers-curious

Chapter 10
 
 
I
 
 
K-nearest neighbors
It just involves a set of five numbers instead of a set of two numbers.
The distance formula is flexible: you could have a set of a 
million
numbers and still use the same old distance formula to find the 
distance. Maybe you’re wondering, “What does 
distance
mean when 
you have five numbers?” The distance tells you how similar those sets of 
numbers are.
Here’s the distance between Priyanka and Justin.
Priyanka and Justin are pretty similar. What’s the difference between 
Priyanka and Morpheus? Calculate the distance before moving on.
Did you get it right? Priyanka and Morpheus are 24 apart. The distance 
tells you that Priyanka’s tastes are more like Justin’s than Morpheus’s.
Great! Now recommending movies to Priyanka is easy: if Justin likes a 
movie, recommend it to Priyanka, and vice versa. You just built a movie 
recommendations system!
If you’re a Netflix user, Netflix will keep telling you, “Please rate more 
movies. The more movies you rate, the better your recommendations 
will be.” Now you know why. The more movies you rate, the more 
accurately Netflix can see what other users you’re similar to.


195
Building a recommendations system
EXERCISES
10.1 
In the Netflix example, you calculated the distance between two 
different users using the distance formula. But not all users rate 
movies the same way. Suppose you have two users, Yogi and Pinky, 
who have the same taste in movies. But Yogi rates any movie he 
likes as a 5, whereas Pinky is choosier and reserves the 5s for 
only the best. They’re well matched, but according to the distance 
algorithm, they aren’t neighbors. How would you take their 
different rating strategies into account? 
10.2
Suppose Netflix nominates a group of “influencers.” For example, 
Quentin Tarantino and Wes Anderson are influencers on Netflix, 
so their ratings count for more than a normal user’s. How would 
you change the recommendations system so it’s biased toward the 
ratings of influencers?
Regression
Suppose you want to do more than just recommend a movie: you want 
to guess how Priyanka will rate this movie. Take the five people closest 
to her.
By the way, I keep talking about the closest five people. There’s nothing 
special about the number 5: you could do the closest 2, or 10, or 10,000. 
That’s why the algorithm is called k-nearest neighbors and not five-
nearest neighbors! 
Suppose you’re trying to guess a rating for 
Pitch Perfect
. Well, how did 
Justin, JC, Joey, Lance, and Chris rate it?


196

Yüklə 348,95 Kb.

Dostları ilə paylaş:
1   ...   91   92   93   94   95   96   97   98   ...   122




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin