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

Unlock the full course today

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

K-nn

K-nn

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

Start my 1-month free trial

K-nn

- [Instructor] The first method of classification that we'll look at, is actually one of the simplest in theory. And that's kNN, which stands for k-nearest neighbors. And this is really simple to execute in R. To do this, I'm going to come down load a few packages including caret, which has several testing and training functions. E1071, which actually comes from a class name, which has several machine learning functions, as well as the other packages we normally get. I'll load those and I will also set the random seed because we're going to have some randomization going on in here. And then, let's import our two datasets that we already prepared at the training data set from Spambase and the testing data set, TST. Now we're going to compute our model on the training data. And to do this, we first have to tell the algorithm exactly how we want to do this. So we're going to set up stat control. That is methods of…

Contents