Tending to classification trees

Supervised Learning in R: Classification

Brett Lantz

Instructor

Pre-pruning

Early Stopping with MaxDepth

Early Stopping with MinSplit

Supervised Learning in R: Classification

Post-pruning

Pruning a Complex Branch

Plotting Error vs. Complexity

Supervised Learning in R: Classification

Pre- and post-pruning with R

# pre-pruning with rpart
library(rpart)
prune_control <- rpart.control(maxdepth = 30, minsplit = 20)

m <- rpart(repaid ~ credit_score + request_amt,
           data = loans,
           method = "class",
           control = prune_control)
# post-pruning with rpart
m <- rpart(repaid ~ credit_score + request_amt,
           data = loans,
           method = "class")

plotcp(m)

m_pruned <- prune(m, cp = 0.20)
Supervised Learning in R: Classification

Let's practice!

Supervised Learning in R: Classification

Preparing Video For Download...