text_plain_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import classification_report

from sklearn.neighbors import KNeighborsClassifier

import numpy as np # linear algebra

from sklearn.neighbors import KNeighborsClassifier
knnscore = []
for i, k in enumerate(range(1, 40)):
    knn = KNeighborsClassifier(n_neighbors=k)
    knn.fit(X_train, y_train)
    knnscore.append(knn.score(X_test, y_test))

knn = KNeighborsClassifier(1 + knnscore.index(np.max(knnscore)))
knn.fit(X_train, y_train)
pred3 = knn.predict(X_test)

from sklearn.ensemble import RandomForestClassifier
rfcscore = []
for i, k in enumerate(range(100, 300, 20)):
    rfc = RandomForestClassifier(n_estimators=k)
    rfc.fit(X_train, y_train)
    rfcscore.append(rfc.score(X_test, y_test))

rfc = RandomForestClassifier(n_estimators=1 + rfcscore.index(np.max(rfcscore)))
rfc.fit(X_train, y_train)
pred5 = rfc.predict(X_test)
print(classification_report(y_test, pred5))