Documente Academic
Documente Profesional
Documente Cultură
KNN Algorithm
Supervised
Lazy learning algorithm – It completely learns from training data only
KNN Classifier sets the benchmark for other complex classifiers such as Artificial neural networks
(ANN) and support vector machines (SVM)
It is slow
Good domain expert on the team is a must in order to use KNN in order to select appropriate set
of features/training set
KNN can be used for classification as well as regression
Whenever we have a new point to classify we find the K nearest neighbors from the training
data set.
The distance calculation in KNN can be done in 3 way:
Euclidean distance
Minkowski distance
Mahalanobis distance
Output of KNN is predicted class
Entire dataset is fed to the model as training dataset a single test sample input/ feature provided by
user is provided to the model Test sample is matched against each training data a class is
predicted for test sample based on the comparison and the distance (nearest)
Leaf size passed to BallTree or KDTree. This can affect the speed of the
construction and query, as well as the memory required to store the tree. The optimal
value depends on the nature of the problem.
The distance metric to use for the tree. The default metric is minkowski, and with p=2 is
equivalent to the standard Euclidean metric.
The number of parallel jobs to run for neighbor’s search. If -1, then the number of jobs
is set to the number of CPU cores. Doesn’t affect fit method.
Power parameter for the Minkowski metric. When p = 1, this is equivalent to using
manhattan_distance (l1), and euclidean_distance (l2) for p = 2. For arbitrary p,
minkowski_distance (l_p) is used.
‘uniform’ : uniform weights. All points in each neighborhood are weighted equally.
‘distance’ : weight points by the inverse of their distance. in this case, closer neighbors
of a query point will have a greater influence than neighbors which are further away.
[callable] : a user-defined function which accepts an array of distances, and returns an
array of the same shape containing the weights.