Machine Learning with caret in R
Max Kuhn
Software Engineer at RStudio and creator of caret
caret
package# Fit a model to the mtcars data
data(mtcars)
model <- lm(mpg ~ hp, mtcars[1:20, ])
# Predict in-sample
predicted <- predict(
model, mtcars[1:20, ], type = "response"
)
# Calculate RMSE
actual <- mtcars[1:20, "mpg"]
sqrt(mean((predicted - actual) ^ 2))
3.172132
Machine Learning with caret in R