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

Plotting Decision trees

Dr. D’Agostino McGowan

1 / 10

Plotting decision trees

There are several R packages that assist with tree plotting

  • rpart.plot
  • partykit
  • rattle
2 / 10

Where to find out more about packages

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

Learn about partykit

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

4 / 10

rpart.plot

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

5 / 10

rpart.plot

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

install.packages("rpart.plot")
5 / 10

rpart.plot

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

install.packages("rpart.plot")
library(rpart.plot)
5 / 10

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)
6 / 10

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)
6 / 10

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 / 10

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 / 10

rpart.plot

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

9 / 10
10:00

Application Exercise

  • Open your application exercise [10]
  • Install rpart.plot
  • Create a plot from your final decision tree
10 / 10

Plotting decision trees

There are several R packages that assist with tree plotting

  • rpart.plot
  • partykit
  • rattle
2 / 10
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