The handy train() function in caret will allow us to find the best hyperparameters for these models. In this recipe, we will use the longley dataset, which is included in R's standard datasets library. This dataset contains the number of people employed (which is our target variable), and several features (such as the number of unemployed, the year, the GNP, the GNP deflator, and the population). There are two challenges here; it only contains annual data from 1947 to 1962, and some of the variables are highly colinear:
- Let's first load the dataset, and build a simple lm() model that will serve as a reference. As can be seen below, we have three variables with a low significance. This model is obviously not very promising ...