问题
I have used leaps package in R to perform forward and backward feature elimination. However, I want automate the cross validation and prediction operations. Therefore, how can I use forward/backward selection in caret?
in leaps package you could do it this way
forward <- regsubsets(x ~ ., data, nvmax = 20,
method = "forward")
回答1:
You should be able to run a stepwise regression in caret::train()
with method=glmStepAIC
from the MASS
package. For details, see the list of models supported by caret on the caret documentation website.
The caret test cases for this model are accessible on the caret GitHub repository.
来源:https://stackoverflow.com/questions/47855807/stepwise-regression-using-caret-in-r