# K Nearest Neighbor Regression Algorithm Explain with Project

In this ML Algorithms course tutorial, we are going to learn “ K Nearest Neighbor Regression in detail. we covered it by practically and theoretical intuition.

1. What is K Nearest Neighbor?
2. What does the K stand for in K nearest neighbors?
3. What is K Nearest Neighbor used for?
4. How do K Nearest Neighbor work?
5. What is K Nearest Neighbor Regression?
6. What is Euclidian Distance Manhattan Distance?
7. What is nearest Neighbour rule?
8. What is K Nearest Neighbor Regression diagram?
9. How to implement K Nearest Neighbor Regression in python using sklearn?

## K Nearest Neighbor Regression Project

```"""
## Business Problem - Predict the Price of Bangalore House

**Using** K Nearest Neighbor Regression - Supervised Machine Learning Algorithm

"""

import pandas as pd

"""## Split Data"""

X = df.drop('price', axis=1)
y = df['price']

print('Shape of X = ', X.shape)
print('Shape of y = ', y.shape)

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=51)

print('Shape of X_train = ', X_train.shape)
print('Shape of y_train = ', y_train.shape)
print('Shape of X_test = ', X_test.shape)
print('Shape of y_test = ', y_test.shape)

"""##K Nearest Neighbor Regression - ML Model Training"""

from sklearn.neighbors import KNeighborsRegressor

regressor = KNeighborsRegressor(n_neighbors=5)
regressor.fit(X_train, y_train)

regressor.score(X_test, y_test)

"""## Predict the value of Home"""

X_test.iloc[-1, :]

regressor.predict([X_test.iloc[-1, :]])

y_test.iloc[-1]

y_pred = regressor.predict(X_test)
y_pred

y_test

```
Top