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.

Solution: KNN

Solution: KNN - Python Tutorial

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

Start my 1-month free trial

Solution: KNN

(upbeat music) - [Instructor] Now that you've taken a moment to try the kNN challenge, I want to show you the solution that I have, which is based on the original demonstration of kNN nearest neighbors. I'm going to start by importing the libraries including several from scikit-learn and then loading the data that we prepared. And to do this, I am going to import the data and then split it into the attribute variables which are used for predicting what's going on, and then the class variable which is the outcome we're trying to predict. And then I'll finish with the class labels, to see whether the cell is benign or malignant. Take a look at the first few rows of the training data. And we have X0 through X8 which are measurements of the cells in the biopsy, and then Y the class, the determination whether it's benign or malignant. We'll train the model, which is a very simple procedure. Once you have the K neighbor's…

Contents