Is there any way to use rpart to grow and/or prune trees up to a certain number of splits?
Illustrated in the example below, the cptable skips certain number of splits (1 and 4). I'm not able to prune this tree to get exactly 1 split (either none or 2 splits).
I tried varying the control settings (cp = 0, xval = 0 and no minsplit or minbucket restrictions), but couldn't find a way for rpart to list all sub trees or build trees of a given number of splits.
Is there any way to use
rpart
to grow and/or prune trees up to a certain number of splits?Illustrated in the example below, the
cptable
skips certain number of splits (1 and 4). I'm not able to prune this tree to get exactly 1 split (either none or 2 splits).I tried varying the control settings (
cp = 0
,xval = 0
and nominsplit
orminbucket
restrictions), but couldn't find a way forrpart
to list all sub trees or build trees of a given number of splits.Created on 2023-03-15 by the reprex package (v2.0.1)
Essentially same question as here on cross validated or here on stack overflow.