A Random Forest prediction model is generated and trained using the ‘mtcars’ dataset. The goal of this model is to predict the fuel consumption (mpg variable) based on the rest of the variables:
customTrainControl <- trainControl(method = "cv", number = 10)
carsRandomForestModelBuilder <- function() {
return(
train(
mpg ~ .,
data = mtcars,
method = "rf",
trControl = customTrainControl
)
)
}
carsRandomForestModelBuilder()
## Random Forest
##
## 32 samples
## 10 predictors
##
## No pre-processing
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 28, 29, 29, 28, 28, 30, ...
## Resampling results across tuning parameters:
##
## mtry RMSE Rsquared MAE
## 2 2.364902 0.9390737 2.037945
## 6 2.227004 0.9623011 1.911614
## 10 2.307681 0.9635279 1.981048
##
## RMSE was used to select the optimal model using the smallest value.
## The final value used for the model was mtry = 6.