20.62 Party Tree

The (Hothorn et al. 2021) package can be used to draw decision trees using partykit::as.party() from (Hothorn and Zeileis 2021) which can be installed from R-Forge:

install.packages("partykit", repos="http://R-Forge.R-project.org")
library(partykit)
class(model)
## [1] "rpart"
plot(as.party(model))

The textual presentation of an rpart decision tree can also be improved using party.

print(as.party(model))
## 
## Model formula:
## rain_tomorrow ~ rain_today + temp_3pm + temp_9am + cloud_3pm + 
##     cloud_9am + pressure_3pm + pressure_9am + humidity_3pm + 
##     humidity_9am + wind_speed_3pm + wind_speed_9am + wind_dir_3pm + 
##     wind_dir_9am + wind_gust_speed + wind_gust_dir + sunshine + 
##     evaporation + rainfall + max_temp + min_temp
## 
## Fitted party:
## [1] root
## |   [2] humidity_3pm < 72.5: No (n = 105547, err = 14.1%)
## |   [3] humidity_3pm >= 72.5
## |   |   [4] humidity_3pm < 83.5
## |   |   |   [5] rainfall < 2.7
## |   |   |   |   [6] wind_gust_speed < 47: No (n = 5118, err = 33.8%)
## |   |   |   |   [7] wind_gust_speed >= 47: Yes (n = 1768, err = 41.9%)
## |   |   |   [8] rainfall >= 2.7: Yes (n = 3275, err = 34.5%)
## |   |   [9] humidity_3pm >= 83.5: Yes (n = 8014, err = 21.3%)
## 
## Number of inner nodes:    4
## Number of terminal nodes: 5

References

Hothorn, Torsten, Kurt Hornik, Carolin Strobl, and Achim Zeileis. 2021. 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/.


Your donation will support ongoing development 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.