June 2016
Beginner to intermediate
304 pages
6h 24m
English
Nearest neighbors model refers to a general class of algorithms that aim to make a decision based on the number of nearest neighbors in the training dataset. Let's see how to find the nearest neighbors.
import numpy as np import matplotlib.pyplot as plt from sklearn.neighbors import NearestNeighbors
# Input data
X = np.array([[1, 1], [1, 3], [2, 2], [2.5, 5], [3, 1],
[4, 2], [2, 3.5], [3, 3], [3.5, 4]])# Number of neighbors we want to find num_neighbors = 3