The caret package allows us to do a variety of things for preprocessing our data, such as scaling, centering, removing variables with very low variability, and projecting it via principal components. The main workhorse for this is the preProcess() function.
In this recipe, we will explore how to undertake several data transformation steps, before modeling using the Boston dataset (included in the MASS package). This is a famous dataset containing house price indexes for several areas in Boston. The objective is to use several metrics for each area and predict the price index there. We will explain how to do it using random forests.
There are essentially two ways of doing this in caret:
- By calling the preProcess= argument in the train function (this is less flexible, but can be used with cross-validation)
- By calling the preProcess() function before calling train...