Go to TogaWare.com Home Page. Data Science Desktop Survival Guide
by Graham Williams
Duck Duck Go



CLICK HERE TO VISIT THE UPDATED SURVIVAL GUIDE

Decision Trees Setup

20180603 Packages used in this chapter include C50, RWeka, party, partykit, rpart, rpart.plot, and rattle.

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 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 in Williams (2017). See Chapter 7 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 x 7
##    date       location max_temp rain_today humidity_9am wind_dir_9am
##    <date>     <chr>       <dbl> <fct>             <int> <ord>       
##  1 2010-09-03 Adelaide     18.3 No                   67 ENE         
##  2 2010-10-30 WaggaWa~     19.3 No                   81 NE          
##  3 2017-04-04 GoldCoa~     25.5 No                   65 S           
##  4 2018-10-28 Witchcl~     24.7 No                   79 SE          
....


Support further development by purchasing the PDF version of the book.
Other online resources include the GNU/Linux Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 2000-2020 Togaware Pty Ltd. . Creative Commons ShareAlike V4.