20.16 Build a Decision Tree Model
As seen from Rattle’s Log tab the decision tree model is built using rpart::rpart(). Once the different template variables have been defined as in Section @ref(dtrees:sec:model_setup) (form, ds, tr, and vars) we can use this template call to build the model:
This is essentially the same as the command used by Rattle except that some parameter settings are removed. These will be explored later.
In the above call to rpart::rpart() we have named each of the arguments. If we have a look at the structure of rpart::rpart() we see that the arguments are in their expected order, and hence the use of the argument names, and , is optional.
## function (formula, data, weights, subset, na.action=na.rpart, method,
## model=FALSE, x=FALSE, y=TRUE, parms, control, cost, ...)
Whilst the argument names are optional they can assist in reading the code, and so the use of argument names in function calls is encouraged.
A textual presentation of the model is concise and informative, once we learn how to read it. Note this tree is different to the previous one we have seen, since we are using a much larger (the full) weather dataset which includes multiple years of daily observations from many different weather stations across Australia.
## n= 192787
##
## node), split, n, loss, yval, (yprob)
## * denotes terminal node
##
## 1) root 192787 41212 No (0.7862304 0.2137696)
## 2) humidity_3pm< 71.5 160906 22093 No (0.8626962 0.1373038) *
## 3) humidity_3pm>=71.5 31881 12762 Yes (0.4003011 0.5996989)
## 6) humidity_3pm< 82.5 17481 8001 No (0.5423031 0.4576969)
## 12) wind_gust_speed< 42 10597 3867 No (0.6350854 0.3649146) *
## 13) wind_gust_speed>=42 6884 2750 Yes (0.3994770 0.6005230) *
## 7) humidity_3pm>=82.5 14400 3282 Yes (0.2279167 0.7720833) *
Refer to Section @ref(dtrees:sec:explain_read_tree) for an explanation of the format of the textual presentation of the decision tree.
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