ComenzarEmpieza gratis

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
)

Este ejercicio forma parte del curso

Machine Learning with caret in R

Ver curso

Instrucciones del ejercicio

  • 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.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# Fit lm model using 5-fold CV: model
model <- train(
  ___, 
  ___,
  method = "lm",
  trControl = trainControl(
    method = "cv", 
    number = ___,
    verboseIter = TRUE
  )
)

# Print model to console
Editar y ejecutar código