text_plain_output_1.png
from sklearn import datasets

from sklearn.model_selection import train_test_split

from sklearn.neighbors import KNeighborsClassifier

from sklearn.neighbors import KNeighborsClassifier

from sklearn.neighbors import KNeighborsClassifier

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

df = pd.read_csv('../input/house-votes.csv', na_values=['?'])
df.replace('^y$', value=1, regex=True, inplace=True)
df.replace('^n$', value=0, regex=True, inplace=True)
df.fillna(0, inplace=True)

df.to_csv('house-votes-edited.csv')

from sklearn.neighbors import KNeighborsClassifier
y = df['party'].values
X = df.drop('party', axis=1).values
knn = KNeighborsClassifier(n_neighbors=6)
knn.fit(X, y)

X_new = np.array([[0.44764519, 0.95034062, 0.43959532, 0.80122238, 0.26844483, 0.45513802, 0.16595416, 0.56314597, 0.87505639, 0.92836397, 0.80958641, 0.01591928, 0.0294, 0.42548396, 0.65489058, 0.77928102]])
X_new.shape

from sklearn.neighbors import KNeighborsClassifier
y = df['party']
X = df.drop(['party'], axis=1).values
knn = KNeighborsClassifier(n_neighbors=6)
knn.fit(X, y)
y_pred = knn.predict(X)
new_prediction = knn.predict(X_new)

from sklearn import datasets
import matplotlib.pyplot as plt
digits = datasets.load_digits()

from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
X = digits.data
y = digits.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)
knn = KNeighborsClassifier(n_neighbors=7)
knn.fit(X_train, y_train)
print(knn.score(X_test, y_test))