Last active
June 13, 2017 06:53
-
-
Save jamesrajendran/5a9f34e3b57e0384361eab58b192e29c to your computer and use it in GitHub Desktop.
metrics comparison of KNeighborClassifier and LinearRegression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn import metrics | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.neighbors import KNeighborsClassifier | |
from sklearn.datasets import load_iris | |
iris = load_iris() | |
X = iris.data | |
y = iris.target | |
logreg = LogisticRegression() | |
logreg.fit(X,y) | |
ypred = logreg.predict(X) | |
print('logistic regression: ', metrics.accuracy_score(ypred,y)) | |
knn5 = KNeighborsClassifier(n_neighbors=5) | |
knn5.fit(X,y) | |
kpred5 = knn5.predict(X) | |
print('KNeighbors 5 Classification: ', metrics.accuracy_score(kpred5,y)) | |
knn1 = KNeighborsClassifier(n_neighbors=1) | |
knn1.fit(X,y) | |
kpred1 = knn.predict(X) | |
print('KNeighbors 1 Classification: ', metrics.accuracy_score(kpred1,y)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment