Exercise

5-fold cross-validation

In this course, you will use a wide variety of datasets to explore the full flexibility of the caret package. Here, you will use the famous Boston housing dataset, where the goal is to predict median home values in various Boston suburbs.

You can use exactly the same code as in the previous exercise, but change the dataset used by the model:

model <- train(
  medv ~ ., 
  Boston, # <- new!
  method = "lm",
  trControl = trainControl(
    method = "cv", 
    number = 10,
    verboseIter = TRUE
  )
)

Next, you can reduce the number of cross-validation folds from 10 to 5 using the number argument to the trainControl() argument:

trControl = trainControl(
  method = "cv", 
  number = 5,
  verboseIter = TRUE
)

Instructions

100 XP
  • Fit an lm() model to the Boston housing dataset, such that medv is the response variable and all other variables are explanatory variables.
  • Use 5-fold cross-validation rather than 10-fold cross-validation.
  • Print the model to the console and inspect the results.