Specify cp value in rpart cross-validation

Hi. I want to do rpart cross-validation and dig inside the k-fold cross-validation model to see results at each fold. Cross-val lets me do this, but only for the model it selected as optimal. I want to do this for an non-optimal model with my choice of cp value, but it won't use my cp value within the trainControl statement. Is there a way to do accomplish this?

testing cv's

this is a scrubbed version of titanic, n= 891

df <- read.csv("https://static-resources.zybooks.com/static/titanic.csv")
colnames(df)[1] <- "survived"
df <- subset(df, select=-c(embarked, embark_town, class, deck, alive))
df$age[is.na(df$age)] <- round(mean(df$age, na.rm = TRUE),0)
df$survived <- factor(df$survived)
train_control <- trainControl(method = "cv", number = 10)
cvmodel <- train(survived ~ ., data = df, method = "rpart", trControl = train_control)
train_control <- trainControl(method = "cv", number = 10, cp = .052632)

Error in trainControl(method = "cv", number = 10, cp = 0.052632) :
unused argument (cp = 0.052632)

[1] 0.8260132

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.