Skip to content

Instantly share code, notes, and snippets.

@hucodelab
Created April 30, 2022 04:08
Show Gist options
  • Select an option

  • Save hucodelab/58e46cff722847159fd92c64d6e1247c to your computer and use it in GitHub Desktop.

Select an option

Save hucodelab/58e46cff722847159fd92c64d6e1247c to your computer and use it in GitHub Desktop.
# let's test several parameters
n_neighbors = [1,5,10,20,50,100]
test_accuracy = {}
train_accuracy = {}
for n in n_neighbors:
clf = KNeighborsClassifier(n_neighbors = n)
clf.fit(X_train,y_train)
test_acc=clf.score(X_test,y_test)
training_acc=clf.score(X_train, y_train)
test_accuracy[n] = test_acc
train_accuracy[n] = training_acc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment