Grokking Algorithms



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

k-nearest 
neighbors
10
Classifying oranges vs. grapefruit
Look at this fruit. Is it an orange or a grapefruit? 
Well, I know that grapefruits are generally bigger 
and redder. 


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? 

Yüklə 348,95 Kb.

Dostları ilə paylaş:
1   ...   89   90   91   92   93   94   95   96   ...   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