Skip to content

Instantly share code, notes, and snippets.

@shayaf84
Last active August 1, 2020 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shayaf84/cff6602ae018dbc96803d6d2eec96cee to your computer and use it in GitHub Desktop.
Save shayaf84/cff6602ae018dbc96803d6d2eec96cee to your computer and use it in GitHub Desktop.
KNN, and Logistic Regression
### Here we load the train and test data for you to use.
(train_data, train_labels) = get_train_data(flatten = True)
(test_data, test_labels) = get_test_data(flatten = True)
############
knn = KNeighborsClassifier(n_neighbors=10)
log_reg = LogisticRegression()
knn.fit(train_data, train_labels)
log_reg.fit(train_data, train_labels)
predictions = knn.predict(test_data)
score = accuracy_score(test_labels, predictions)
print("KNN accuracy:",score)
predictions = log_reg.predict(test_data)
score = accuracy_score(test_labels, predictions)
print("Logistic Regression accuracy:",score)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment