Fit regression and classification trees using rpart in R
A dataset is given and you must fit a decision tree using rpart() and then prune it.
Use rpart(y ~ ., data = df, method = "anova" or "class") with control parameters cp (complexity) and minsplit. Examine the cp table with printcp() and select the cp at the minimum xerror (or one-SE rule). Prune with prune(tree, cp = chosen_cp). Visualize with rpart.plot() and interpret each split path.
rpart(formula, method, control); printcp() then prune(tree, cp).