+ - 0:00:00
Notes for current slide
Notes for next slide

Plotting Decision trees

Dr. D’Agostino McGowan

1 / 11
05:00

📖 Take 06 Assessment in Canvas

2 / 11

Plotting decision trees

There are several R packages that assist with tree plotting

  • rpart.plot
  • partykit
  • rattle
3 / 11

Where to find out more about packages

  1. Vignettes
  2. Journal Article (R Journal is great)
  3. Rstudio Community
  4. StackOverflow
  5. Twitter
4 / 11
05:00

Learn about partykit

Google partykit to find out how more about it (hint: use key words like rstats and decision tree plots)

5 / 11

rpart.plot

We're going to focus on rpart.plot, but feel free to try the others!

6 / 11

rpart.plot

We're going to focus on rpart.plot, but feel free to try the others!

install.packages("rpart.plot")
6 / 11

rpart.plot

We're going to focus on rpart.plot, but feel free to try the others!

install.packages("rpart.plot")
library(rpart.plot)
6 / 11

rpart.plot

tree_spec <- decision_tree(
cost_complexity = 0.1,
tree_depth = 10,
mode = "regression") %>%
set_engine("rpart")
model <- fit(tree_spec,
Salary ~ Hits + Years + PutOuts + RBI + Walks + Runs,
data = baseball)
7 / 11

rpart.plot

tree_spec <- decision_tree(
cost_complexity = 0.1,
tree_depth = 10,
mode = "regression") %>%
set_engine("rpart")
model <- fit(tree_spec,
Salary ~ Hits + Years + PutOuts + RBI + Walks + Runs,
data = baseball)
rpart.plot(model$fit,
roundint = FALSE)
7 / 11

rpart.plot

tree_spec <- decision_tree(
cost_complexity = 0.1,
tree_depth = 10,
mode = "regression") %>%
set_engine("rpart")
model <- fit(tree_spec,
Salary ~ Hits + Years + PutOuts + RBI + Walks + Runs,
data = baseball)
rpart.plot(model$fit,
roundint = FALSE)
8 / 11

rpart.plot

tree_spec <- decision_tree(
cost_complexity = 0.1,
tree_depth = 10,
mode = "regression") %>%
set_engine("rpart")
model <- fit(tree_spec,
Salary ~ Hits + Years + PutOuts + RBI + Walks + Runs,
data = baseball)
rpart.plot(model$fit,
roundint = FALSE)
9 / 11

rpart.plot

rpart.plot(model$fit,
roundint = FALSE)

10 / 11
10:00

AE 05 - Regression trees

  1. Open your application exercise (05) from last week
  2. Install rpart.plot
  3. Create a plot from your final decision tree
  4. Knit, Commit, Push. Be sure to have the final results pushed to GitHub by April 8 at noon
11 / 11
05:00

📖 Take 06 Assessment in Canvas

2 / 11
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow