
# coding: utf-8

# In[30]:


import os


# In[31]:


os.getcwd()


# In[32]:


os.chdir("C:/Users/Dheeraj B/Desktop/dataset")


# In[33]:


ls


# In[34]:


import pandas as pd
import numpy as np


# In[35]:


from sklearn.neighbors import KNeighborsClassifier


# In[36]:


df = pd.read_csv("votes.csv")


# In[37]:


df.info()


# In[38]:


knn = KNeighborsClassifier(n_neighbors=5)


# In[39]:


df.head()


# In[40]:


X = df.drop(["party"], axis=1)


# In[41]:


Y =  df["party"]


# In[42]:


X.shape


# In[43]:


Y.shape


# In[48]:


from sklearn.preprocessing import LabelEncoder


# In[49]:


df = df.apply(LabelEncoder().fit_transform)


# In[50]:


df.head()


# In[52]:


X = df.drop(["party"], axis=1)
Y =  df["party"]


# In[54]:


knn.fit(X,Y)


# In[55]:


train = df.iloc[:400]


# In[56]:


test= df.iloc[400:]


# In[66]:


# Create arrays for the features and the response variables
y = train["party"].values
x=  train.drop('party',axis=1).values


# In[67]:


model1 = knn.fit(X,Y)


# In[69]:


y_test = test["party"]
test_pred = test.drop(["party"], axis =1)


# In[70]:


y_pred = model1.predict(test_pred)


# In[71]:


y_pred


# In[72]:


y_test


# In[73]:


list(y_pred)


# In[74]:


mis_classified = []
for x ,y in zip(y_test,y_pred):
    if x!=y:
        mis_classified.append(x)
print (1-(len(mis_classified)/len(y_test)))        


# In[75]:


df.head()


dc3a52f38095cda91c52d636a043cb701a299f22
<mask token>

<mask token>
os.getcwd()
os.chdir('C:/Users/Dheeraj B/Desktop/dataset')
ls
<mask token>
df.info()
<mask token>
df.head()
<mask token>
X.shape
Y.shape
<mask token>
df.head()
<mask token>
knn.fit(X, Y)
<mask token>
y_pred
y_test
list(y_pred)
<mask token>
for x, y in zip(y_test, y_pred):
    if x != y:
        mis_classified.append(x)
print(1 - len(mis_classified) / len(y_test))
df.head()

<mask token>
os.getcwd()
os.chdir('C:/Users/Dheeraj B/Desktop/dataset')
ls
<mask token>
df = pd.read_csv('votes.csv')
df.info()
knn = KNeighborsClassifier(n_neighbors=5)
df.head()
X = df.drop(['party'], axis=1)
Y = df['party']
X.shape
Y.shape
<mask token>
df = df.apply(LabelEncoder().fit_transform)
df.head()
X = df.drop(['party'], axis=1)
Y = df['party']
knn.fit(X, Y)
train = df.iloc[:400]
test = df.iloc[400:]
y = train['party'].values
x = train.drop('party', axis=1).values
model1 = knn.fit(X, Y)
y_test = test['party']
test_pred = test.drop(['party'], axis=1)
y_pred = model1.predict(test_pred)
y_pred
y_test
list(y_pred)
mis_classified = []
for x, y in zip(y_test, y_pred):
    if x != y:
        mis_classified.append(x)
print(1 - len(mis_classified) / len(y_test))
df.head()

import os
os.getcwd()
os.chdir('C:/Users/Dheeraj B/Desktop/dataset')
ls
import pandas as pd
import numpy as np
from sklearn.neighbors import KNeighborsClassifier
df = pd.read_csv('votes.csv')
df.info()
knn = KNeighborsClassifier(n_neighbors=5)
df.head()
X = df.drop(['party'], axis=1)
Y = df['party']
X.shape
Y.shape
from sklearn.preprocessing import LabelEncoder
df = df.apply(LabelEncoder().fit_transform)
df.head()
X = df.drop(['party'], axis=1)
Y = df['party']
knn.fit(X, Y)
train = df.iloc[:400]
test = df.iloc[400:]
y = train['party'].values
x = train.drop('party', axis=1).values
model1 = knn.fit(X, Y)
y_test = test['party']
test_pred = test.drop(['party'], axis=1)
y_pred = model1.predict(test_pred)
y_pred
y_test
list(y_pred)
mis_classified = []
for x, y in zip(y_test, y_pred):
    if x != y:
        mis_classified.append(x)
print(1 - len(mis_classified) / len(y_test))
df.head()


# coding: utf-8

# In[30]:


import os


# In[31]:


os.getcwd()


# In[32]:


os.chdir("C:/Users/Dheeraj B/Desktop/dataset")


# In[33]:


ls


# In[34]:


import pandas as pd
import numpy as np


# In[35]:


from sklearn.neighbors import KNeighborsClassifier


# In[36]:


df = pd.read_csv("votes.csv")


# In[37]:


df.info()


# In[38]:


knn = KNeighborsClassifier(n_neighbors=5)


# In[39]:


df.head()


# In[40]:


X = df.drop(["party"], axis=1)


# In[41]:


Y =  df["party"]


# In[42]:


X.shape


# In[43]:


Y.shape


# In[48]:


from sklearn.preprocessing import LabelEncoder


# In[49]:


df = df.apply(LabelEncoder().fit_transform)


# In[50]:


df.head()


# In[52]:


X = df.drop(["party"], axis=1)
Y =  df["party"]


# In[54]:


knn.fit(X,Y)


# In[55]:


train = df.iloc[:400]


# In[56]:


test= df.iloc[400:]


# In[66]:


# Create arrays for the features and the response variables
y = train["party"].values
x=  train.drop('party',axis=1).values


# In[67]:


model1 = knn.fit(X,Y)


# In[69]:


y_test = test["party"]
test_pred = test.drop(["party"], axis =1)


# In[70]:


y_pred = model1.predict(test_pred)


# In[71]:


y_pred


# In[72]:


y_test


# In[73]:


list(y_pred)


# In[74]:


mis_classified = []
for x ,y in zip(y_test,y_pred):
    if x!=y:
        mis_classified.append(x)
print (1-(len(mis_classified)/len(y_test)))        


# In[75]:


df.head()

