From the course: Applied Machine Learning: Supervised Learning

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Solution: A classification model

Solution: A classification model

- [Instructor] Okay, let's look at the solution for 3.5. So I'm going to go up to my K-nearest neighbors model, which is right up here. Here's our pipeline. I'm actually going to take this. If you click on the left-hand side here, you can see to copy this, I'm going to copy that whole cell. I'm going to paste it right down here. Okay, so here is our cell, and you can see that right here, we have 5 as our value. And I'm going to come up here and say best_k is equal to 0 and best_accuracy is equal to 0. And then I'm going to say for k in range, and we're going to do, let's do 1 through, I'm going to do 21. So because the range in Python is the half open interval, it includes the start value but not the end value. I'm going to go up to 22, and then I'm going to say that the step is equal to 2. So I don't have to do this, but generally, you want your case to be odd because it's going to be voting. Then what we'll do is we'll indent this portion here and we will say if accuracy K-nearest…

Contents