KNN (K-Nearest Neighbors)
Explore the fundamentals of the K-Nearest Neighbors (KNN) algorithm as a non-parametric, instance-based learning method used for classification and regression. Understand how to select the number of neighbors, calculate distances, and evaluate model performance. This lesson helps you build and fine-tune KNN models using Scikit-Learn, highlighting practical considerations and computational challenges.
We'll cover the following...
KNN stands for the k-nearest neighbor algorithm which is a non-parametric method used for classification and regression. In both cases, the input consists of the k closest training examples in the feature space. KNN is a type of instance-based learning or lazy learning. Lazy learning means this model doesn’t need any training process. Non-parametric means there is no assumption for the distribution of data. Instance-based means you need to store all data points.
How does the KNN work?
Let’s follow the steps below:
- Define
K.Kis a hyperparameter, which defines the number of neighbors we used to do the prediction work. - After defining the
K, the model is already generated. - Input a new sample,