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.
Building KNN models for regression
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 the R working directory. The file has data about several school districts in the US. The following table describes the variables:
Variable |
Meaning |