Classifying using the KNN approach

The class package contains the knn function for KNN classification.

Getting ready

If you have not already installed the class and caret packages, install them now. Download the data files for this chapter from the book's website and place the vacation-trip-classification.csv file in your R working directory. KNN requires all the independent/predictor variables to be numeric, and the dependent variable or target to be categorical. So, if needed, you should first convert variables accordingly—refer to the recipes Creating dummies for categorical variables and Binning numerical data in Chapter, Acquire and Prepare the Ingredients – Your Data.

How to do it...

To classify using the K-Nearest Neighbours method, follow ...

Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.