20.1 Decision Trees Setup

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

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: 275,410 × 7
##    date       location    pressure_3pm sunshine temp_9am max_temp wind_speed_9am
##    <date>     <chr>              <dbl>    <dbl>    <dbl>    <dbl>          <dbl>
##  1 2015-04-06 Bendigo            1005.     NA       12.6     18.1              0
##  2 2010-05-25 Launceston         1014.     NA        9.5     15.3              7
##  3 2024-09-17 Launceston           NA      NA       11.1     15.4             20
##  4 2013-11-12 NorahHead          1012.     NA       17.5     21                9
....

References

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


If you find this curated material useful then you can consider a donation to support it's ongoing availability and give you access to the PDF version of this book. The material has been scoped up by Generative AI without permission or any kind of recompense so do consider a donation if you can afford it. Unlike Generative AI your access to this materials is freely given. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Togaware has a 30 year tradition of making popular open source software which includes sold privacy preserving productivity apps, rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0