 Data Science Desktop Survival Guide by Graham Williams Desktop Survival Project Home Preface Data Science Introducing R R Constructs R Tasks R Strings R Read, Write, and Create Data Template Data Exploration Data Wrangling Data Visualisation Statistics ML Template ML Scenarios ML Activities ML Applications ML Algorithms Cluster Analysis Decision Trees Computer Vision Graph Data Privacy Literate Data Science Coding with Style Resources Bibliography Index

## Regression Trees

The discussion so far has dwelt on classification trees. Regression trees are similarly well catered for in R.

We can plot regression trees as with classification trees, but the node information will be different and some options will not make sense. For example, extra= only makes sense for 100 and 101.

First we will build regression tree:

target <- "risk_mm"
vars <- c(inputs, target)
form <- formula(paste(target, "~ ."))
(model <- rpart(formula=form, data=ds[tr, vars]))
 ```## n=120704 (3018 observations deleted due to missingness) ## ## node), split, n, deviance, yval ## * denotes terminal node ## ## 1) root 120704 8785460.0 2.272201 ## 2) humidity_3pm< 83.5 112864 3791677.0 1.486089 ## 4) humidity_3pm< 66.5 94010 1731286.0 0.983856 * ## 5) humidity_3pm>=66.5 18854 1918441.0 3.990326 * ## 3) humidity_3pm>=83.5 7840 3919967.0 13.589010 ## 6) rainfall< 39.1 7439 2505518.0 11.983020 ## 12) min_temp< 15.95 5209 838540.7 9.100749 * ## 13) min_temp>=15.95 2230 1522622.0 18.715650 * ## 7) rainfall>=39.1 401 1039330.0 43.381800 * ```