From the course: Data Science Foundations: Data Mining in Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

KNN

KNN - Python Tutorial

From the course: Data Science Foundations: Data Mining in Python

Start my 1-month free trial

KNN

- [Instructor] In the natural world, it's often the case that like goes with like and the k-nearest neighbors algorithm, or kNN, is an example of that where the k is the numbers of neighbors you want to look at. The idea here is that you put your data in a multidimensional space and if you're trying to find out if a new case should go into one category or another, you look at its closest neighbors in that multidimensional space and see what's most common among them. Theoretically, it's a pretty simple thing. To do this in Python, we're going to start by loading a number of packages, including several functions from scikit-learn. Once we get those, we can load the data. We're going to load the training data from this local CSV file and then we'll split it up and then we'll do the same thing with the testing data and then we'll define the class labels. Let's take a look at the first few rows of the training data.…

Contents