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
)
本练习是课程的一部分
Machine Learning with caret in R
练习说明
- Fit an
lm()model to theBostonhousing dataset, such thatmedvis 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.
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Fit lm model using 5-fold CV: model
model <- train(
___,
___,
method = "lm",
trControl = trainControl(
method = "cv",
number = ___,
verboseIter = TRUE
)
)
# Print model to console