text_plain_output_1.png
from sklearn.metrics import confusion_matrix,classification_report

from sklearn.model_selection import train_test_split

from sklearn.neighbors import KNeighborsClassifier

from sklearn.svm import SVC

import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

plt.style.use('ggplot')

zoo = pd.read_csv('../input/zoo.csv')

data = zoo.copy()
data.drop('animal_name', axis=1, inplace=True)

x = data.drop('class_type', axis=1)
y = data.class_type.values

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.4, random_state=42)

from sklearn.svm import SVC
svm = SVC(random_state=42, kernel='linear')
svm.fit(x_train, y_train)
y_pred_svm = svm.predict(x_test)

from sklearn.metrics import confusion_matrix, classification_report
cm_svm = confusion_matrix(y_test, y_pred_svm)
cr_svm = classification_report(y_test, y_pred_svm)

from sklearn.neighbors import KNeighborsClassifier
scr_max = 0
knn_test_score_list = []
knn_train_score_list = []
for i in range(1, x_train.shape[0] + 1):
    knn = KNeighborsClassifier(n_neighbors=i)
    knn.fit(x_train, y_train)
    knn_test_scr = knn.score(x_test, y_test)
    knn_test_score_list.append(knn_test_scr)
    knn_train_scr = knn.score(x_train, y_train)
    knn_train_score_list.append(knn_train_scr)
    if knn_test_scr >= scr_max:
        scr_max = knn_test_scr
        index = i

knn = KNeighborsClassifier(n_neighbors=1)
knn.fit(x_train, y_train)
y_pred_knn = knn.predict(x_test)
cr_knn = classification_report(y_test, y_pred_knn)
cm_knn = confusion_matrix(y_test, y_pred_knn)
print('confusion matrix : \n', cm_knn)
print('classification report : \n', cr_knn)