I have generated a simple tree using the rpart()
function, however I would like to be able to stop the second split at Petal.Length < 4.9
before it splits by Petal.Width
, however I would not like to alter anything else in the tree. The only thing that I have found is that I can use the subset function in order to manually grow the tree, but this process can be very tedious. Any suggestions on a function that could possibly be used? The code used to generate the tree is:
library(rpart)
library(datasets)
data("iris")
library(rpart.plot)
Sample <-sample.int(n = nrow(iris), size = floor(.7*nrow(iris)), replace = F)
train <- iris[Sample, ]
test <- iris[-Sample, ]
m1 <- rpart(Species~Sepal.Width + Sepal.Length + Petal.Length + Petal.Width,
data = train, control = rpart.control(cp = 0.005), method = "anova")
rpart.plot(m1, type = 3, fallen.leaves = TRUE)