With scikit-learn in python.This aims to be an applied guide to utilizing the K-Nearest-Neighbors (KNN) method for solving business problems in python. The most popular use-case of KNN is in classification. Interestingly though, it is applicable to KNN regressions as well.

This aims to be an applied guide to utilizing the K-Nearest-Neighbors (KNN) method for solving business problems in python. The most popular use-case of KNN is in classification. Interestingly though, it is applicable to KNN regressions as well.

Beginning with the foundations of KNN classifier models. KNN classifier models work in 3 broad steps to predict labels for unprecedented feature values (which are not in the training data).

- It memorizes the whole training test set — specifically which features resulted in which y label.
- It defines the K-nearest most similar instances, where K is a user defined integer. For a given data point, it looks at the nearest features and their respective labels.
- It predicts the new label as a function of nearest neighbors’ labels. Usually, this is a majority vote.

Circling back to KNN regressions: the difference is that KNN regression models works to predict new values from a continuous distribution for unprecedented feature values. Conceptually, how it arrives at a the predicted values is similar to KNN classification models, except that it will take the average value of it’s K-nearest neighbors.

Let’s first import the required packages:

*numpy _and _pandas*: data and array manipulation in python*pyploy module*from the _matplotlib library: _data visualisation- _sklearn modules _for creating train-test splits, and creating the KNN object.

```
## Packages
%matplotlib notebook
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.preprocessing import MinMaxScaler
```

Applied Data Analysis in Python Machine learning and Data science, we will investigate the use of scikit-learn for machine learning to discover things about whatever data may come across your desk.

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.