I am developing a regression model using the rpart function in R. This function cross-validates over the parameter cp.
Is there a way to control what values of cp and how many are cross-validated over?
I am developing a regression model using the rpart function in R. This function cross-validates over the parameter cp.
Is there a way to control what values of cp and how many are cross-validated over?
You can do something like
fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis,
control = rpart.control(cp = 0.05))
Also take a look at the rpart.control options http://www.inside-r.org/r-doc/rpart/rpart.control
It would probably be much easier to use caret
library(caret)
data(iris)
tc <- trainControl("cv",10)
rpart.grid <- expand.grid(.cp=0.2)
train.rpart <- train(Kyphosis ~ Age + Number + Start,
data=kyphosis, method="rpart",
trControl=tc, tuneGrid=rpart.grid)