import pandas as pd
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix,accuracy_score
import matplotlib.pyplot as plt

Data=pd.read_csv("Immunotherapy.csv")
Data=Data.values
X=Data[:,:-1]
y=Data[:,-1]

X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2)
knn=KNeighborsClassifier()
knn.fit(X_train,y_train)
p=knn.predict(X_test)
print "Confusion Matrix : \n ",confusion_matrix(p,y_test)
print "Accuracy Score : \n ",accuracy_score(p,y_test)
s=[]
for i in range(1,26):
    knn=KNeighborsClassifier(n_neighbors=i)
    knn.fit(X_train,y_train)
    p=knn.predict(X_test)
    acs=accuracy_score(p,y_test)
    s.append(acs)
plt.plot(range(1,26),s)
plt.title('Number of Neighbors Vs Accuracy Score ')
plt.xlabel('Number of Neighbors')
plt.ylabel('Accuracy Score')
plt.show()

