188
Chapter 10
I
k-nearest neighbors
My thought process is something like this: I have a graph in my mind.
Generally speaking,
the bigger, redder fruit are grapefruits. This fruit
is big and red, so it’s probably a grapefruit.
But what if you get a fruit
like this?
How would you
classify
this fruit? One way is to look at the neighbors of
this spot. Take a look at the three closest neighbors of this spot.
189
Building a recommendations system
More neighbors are oranges than grapefruit. So this fruit is probably an
orange. Congratulations: You just used the
k-nearest neighbors
(KNN)
algorithm for
classification
! The whole algorithm is pretty simple.
The KNN algorithm is simple but useful! If you’re trying to classify
something, you might want to try KNN first. Let’s look at a more
real-world example.
Building a recommendations system
Suppose you’re Netflix, and
you want to build a movie
recommendations system for your users. On a high level, this
is similar to the grapefruit problem!
190
Chapter 10
I
k-nearest neighbors
You can plot every user on a graph.
These users
are plotted by similarity, so users with similar taste are
plotted closer together. Suppose you want to recommend movies for
Priyanka. Find the five users closest to her.
Justin, JC, Joey, Lance, and Chris all have similar taste in movies. So
whatever
movies
they
like, Priyanka will probably like too!
Once you have this graph, building a recommendations system is easy.
If Justin likes a movie, recommend it to Priyanka.
191
Building a recommendations system
But there’s still a big piece missing. You graphed the users by similarity.
How do you figure out how similar two users are?
Dostları ilə paylaş: