Data Science Desktop Survival Guide
by Graham Williams |
|||||
Build a Decision Tree Model |
As seen from Rattle's Log tab the decision tree model is built using rpart(). Once the different template variables have been defined as in Section 18.2 (form, ds, tr, and vars) we can use this template call to build the model:
library(rpart)
model <- rpart(formula=form, data=ds[tr, vars], model=TRUE)
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, formula= and data=, is optional.
|
str(rpart)
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.
|
model
Refer to Section 18.8 for an explanation of the format of the textual presentation of the decision tree.
|