20.1 Decision Trees Setup

20180603 Packages used in this chapter include C50 (Kuhn and Quinlan 2022), RWeka (Hornik 2021), party (Hothorn et al. 2022), partykit (Hothorn and Zeileis 2021), rpart (Therneau and Atkinson 2022), rpart.plot (Milborrow 2021), and rattle (G. Williams 2020).

Packages are loaded into the currently running R session from your local library directories on disk. Missing packages can be installed using utils::install.packages() within R. On Ubuntu, for example, R packages can also be installed using $ wajig install r-cran-<pkgname>.

# Load required packages from local library into the R session.

library(C50)          # Original C5.0 implementation.
library(RWeka)        # Weka decision tree J48.
library(party)        # Conditional decision trees ctree().
library(partykit)     # Convert rpart object to BinaryTree
library(rattle)       # GUI for building trees and fancy tree plot.
library(rpart)        # Popular decision tree algorithm.
library(rpart.plot)   # Enhanced tree plots.

The rattle::weatherAUS dataset is loaded into the template variable ds and further template variables are setup as introduced by Graham J. Williams (2017). See Chapter 8 for details.

dsname <- "weatherAUS"
ds     <- get(dsname)
    
nobs   <- nrow(ds)

vnames <- names(ds)
ds    %<>% clean_names(numerals="right")
names(vnames) <- names(ds)

vars   <- names(ds)
target <- "rain_tomorrow"
vars   <- c(target, vars) %>% unique() %>% rev()

It is always useful to remind ourselves of the dataset with a random sample:

ds  %>% sample_frac() %>% select(date, location, sample(3:length(vars), 5))
## # A tibble: 176,747 × 7
##    date       location     wind_gust_dir pressure_9am temp_9am max_temp sunshine
##    <date>     <chr>        <ord>                <dbl>    <dbl>    <dbl>    <dbl>
##  1 2014-11-05 Albury       WNW                  1013.     15.8     26       NA  
##  2 2009-08-10 Penrith      W                      NA       6       17.8     NA  
##  3 2015-12-16 MelbourneAi… S                    1017      18.7     29.7     11  
##  4 2014-03-19 CoffsHarbour SSE                  1023.     24.8     27.3     NA  
##  5 2010-11-04 Melbourne    S                    1025.     12.9     18.2      8.1
##  6 2013-05-04 Williamtown  SSE                  1018.     18       24.5     NA  
##  7 2009-03-13 Watsonia     NW                   1017.     17.4     30.8      9.8
##  8 2011-12-09 MountGambier SE                   1009.     18.2     23.9      1.4
##  9 2013-03-24 Williamtown  W                    1016.     21.7     32.1     NA  
## 10 2015-11-26 Williamtown  NW                   1002.     30.7     41.6     NA  
## # … with 176,737 more rows

References

Hornik, Kurt. 2021. RWeka: R/Weka Interface. https://CRAN.R-project.org/package=RWeka.
Hothorn, Torsten, Kurt Hornik, Carolin Strobl, and Achim Zeileis. 2022. Party: A Laboratory for Recursive Partytioning. http://party.R-forge.R-project.org.
Hothorn, Torsten, and Achim Zeileis. 2021. Partykit: A Toolkit for Recursive Partytioning. http://partykit.r-forge.r-project.org/partykit/.
Kuhn, Max, and Ross Quinlan. 2022. C50: C5.0 Decision Trees and Rule-Based Models. https://topepo.github.io/C5.0/.
Milborrow, Stephen. 2021. Rpart.plot: Plot Rpart Models: An Enhanced Version of Plot.rpart. http://www.milbo.org/rpart-plot/index.html.
Therneau, Terry, and Beth Atkinson. 2022. Rpart: Recursive Partitioning and Regression Trees. https://CRAN.R-project.org/package=rpart.
Williams, Graham. 2020. Rattle: Graphical User Interface for Data Science in r. https://rattle.togaware.com/.
Williams, Graham J. 2017. The Essentials of Data Science: Knowledge Discovery Using r. The r Series. CRC Press.


Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0