July 2017
Intermediate to advanced
382 pages
9h 13m
English
The other really helpful method that knn provides is called findNearest. It can be used to predict the label of a new data point based on its nearest neighbors.
Thanks to our generate_data function, it is actually really easy to generate a new data point! We can think of a new data point as a dataset of size 1:
In [17]: newcomer, _ = generate_data(1)Out[17]: newcomer
Our function also returns a random label, but we are not interested in that. Instead, we want to predict it using our trained classifier! We can tell Python to ignore an output value with an underscore (_).
Let's have a look at our town map again. We will plot the training set as we did earlier, but also add the new data point as a green ...
Read now
Unlock full access