O'Reilly logo

R Data Analysis Cookbook by Shanthi Viswanathan, Viswa Viswanathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building KNN models for regression

The FNN package provides the necessary functions to apply the KNN technique for regression. In this recipe, we look at the use of the knn.reg function to build the model and then the process of predicting with the model as well. We also show some additional convenience mechanisms to make the process easier.

Getting ready

Install the FNN, dummies, caret, and scales packages if you do not already have them installed. If you have not already downloaded the data files for this chapter, do so now and ensure that the education.csv file is in R working directory. The file has data about several school districts in the US. The following table describes the variables:

Variable

Meaning

state

US state code

region ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required