Skip to content

Supervised Learning with scikit-learn

Run the hidden code cell below to import the data used in this course.


1 hidden cell

Take Notes

Add notes about the concepts you've learned and code cells with code you want to keep.

Spinner
DataFrameas
df
variable

Add your notes here

# Add your code snippets here
# Create neighbors
neighbors = np.arange(X_test, y_test)
train_accuracies = {}
test_accuracies = {}

for neighbor in neighbors:
  
	# Set up a KNN Classifier
	knn = KNeighborsClassifier(neighbors=neighbor)
  
	# Fit the model
	knn.fit(X_test, y_test)
  
	# Compute accuracy
	train_accuracies[neighbor] = knn.score(X_train, Y_train)
	test_accuracies[neighbor] = knn.score(X_test, y_test)
print(neighbors, '\n', train_accuracies, '\n', test_accuracies)