caret is a magical package for doing machine learning in R. Look at this code for running a regularized regression:
library(caret)
inTrain <- createDataPartition(y = mtcars$mpg,
p = 0.75,
list = FALSE)
reg_mod <- train(
mpg ~ .,
data = mtcars[inTrain, ],
method = "glmnet",
tuneLength = 10,
preProc = c("center", "scale"),
trControl = trainControl(method = "cv", number = 10)
)
The two function calls in the expression above perform these operations:
Create a training set containing a random sample of 75% of the initial sample
Center and scale all predictors ...
[Read more...]