## k nearest neighbor python 3.10

# k nearest neighbor python numpy language:

Welcome everyone in python crash course (Machine learning). This is first part of this section,if you want to learn ** SVM in python **then click on it.

K Nearest Neighbors method also used for data prediction purpose, so in his section we will learn K Nearest Neighbors predict method.

k nearest neighbor python numpy language |

## How do you use K nearest neighbor in Python language in smart way?

**In this project following steps are used to performed operation:**

- Import
**k**–**nearest neighbor**algorithm package. - Then Create feature and target variables using function.
- Split data into x/y_training and x/y_test data.
- Generate a
**k**–**NN**value model**using neighbor method**. - Train or fit the data into the different model methods.
- finally Predict the future data

### What is K nearest neighbor used for?

suppose you have been given a classified data set from a any popular company,they give you the data and the target classes and say predicts a class for a new data point based off of the features.

Let’s do it!

#### k nearest neighbor python 3.10

Get the Data

Set index_col=0

df.head()

Standardize the Variables K Nearest Neighbors method

In the next step we drop the TARGETC CLASSES from the data because this type of data affect on the prediction.

df_feat.head()

Train Test Split method:

Using KNN method

Remember we will start with k=1 value.

Predictions and Evaluations using knn

Let’s start to evaluate our KNN model!

print(confusions_matrix(y_test,pred))

print(classification_report(y_test,pred))

Choosing a correct value for K for this

we use the elbow method to pick a correct K Value: