Machine LearningLesson 91Free preview
K-nearest neighbors
This lesson is part of Python · All levels
Summary
K-Nearest Neighbors (KNN) classifies new data based on the majority of k's nearest neighbors in the feature space. When the prediction is made, the model calculates the distance of the new data to the entire training data, sorts it, and then takes the nearest k to select the class. The k-value that is too small makes the model sensitive to noise, while too large makes the boundary of the cluster blurry. KNN is a lazy algorithm because it doesn't train anything, all the calculations happen when the prediction is made.
Key points
- KNN determines the class of the majority of k's nearest neighbors
- The k-value sets the balance between sensitivity and noise sensitivity
- The feature is mandatory discaling because the KNN depends on the distance
- KNN doesn't train models, calculations are done when prediction is in order.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.