-nearest neighbors -nearest neighbors classification let {(xi yi )}ni= be the training setwith yi { }and let be new feature vector define ( ( (nas the feature vectors ordered by closeness to in some distance dist(xxi ) the euclidean distance kxx let ( :{( ( ( ( (ky( )be the subset of that contains feature vectors xi that are closest to then the -nearest neighbors classification rule classifies according to the most frequently occurring class labels in (xif two or more labels receive the same number of votesthe feature vector is classified by selecting one of these labels randomly with equal probability for the case the set (xcontains only one elementsay ( )and is classified as this divides the space into regions ri { dist(xxi dist(xx ) } for feature space with the euclidean distancethis gives voronoi tessellation of the feature spacesimilar to what was done for vector quantization in section example (nearest neighbor classificationthe python program below simulates random points above and below the line points above the line have label and points below this line have label figure shows the voronoi tessellation obtained from the -nearest neighbor classification figure the -nearest neighbor algorithm divides up the space into voronoi cells nearestnb py import numpy as np from numpy random import rand randn import matplotlib pyplot as plt from scipy spatial import voronoi voronoi_plot_