Key Concepts

Review core concepts you need to learn to master this subject

KNN Classification Algorithm in Scikit Learn

from sklearn.neighbors import KNeighborsClassifier KNNClassifier = KNeighborsClassifier(n_neighbors=5) KNNClassifier.fit(X_train, y_train) KNNClassifier.predict(X_test)

Scikit-learn is a very popular Machine Learning library in Python which provides a KNeighborsClassifier object which performs the KNN classification. The n_neighbors parameter passed to the KNeighborsClassifier object sets the desired k value that checks the k closest neighbors for each unclassified point.

The object provides a .fit() method which takes in training data and a .predict() method which returns the classification of a set of data points.

Distance Formula
Lesson 1 of 2

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo