import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import warnings
'ignore')
warnings.filterwarnings(
= pd.read_csv('_data/08.csv')
dataset = dataset.iloc[:, :-1].values
x = dataset.iloc[:, -1].values y
K Nearest Neighbors
machine learning
preprocessing
from sklearn.model_selection import train_test_split
= train_test_split(x, y, test_size=0.25) x_train, x_test, y_train, y_test
from sklearn.preprocessing import StandardScaler
= StandardScaler()
sc
= sc.fit_transform(x_train)
x_train = sc.transform(x_test) x_test
Modeling
from sklearn.neighbors import KNeighborsClassifier
= KNeighborsClassifier()
classifier classifier.fit(x_train, y_train)
KNeighborsClassifier()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
KNeighborsClassifier()
Predict
from sklearn.metrics import confusion_matrix, accuracy_score
= classifier.predict(x_test)
y_pred print(confusion_matrix(y_test, y_pred))
accuracy_score(y_test, y_pred)
[[57 5]
[ 5 33]]
0.9