O'Reilly logo

Practical Predictive Analytics by Ralph Winters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Decision tree using Rpart

We will run our rpart algorithm as a regression tree. Recall that a regression tree is used when the output variable is in numerical form, rather than nominal form. Before we do that, we need to map our frisked=Y/N to frisked=1/0 and specify method="anova" in the call.

The last line of code (fit) will print out the decision rules to the console as text.

The height, sex, age, and city parameters appear as the primary splits:

set.seed(123) library(rpart) dflocal$frisked_bin <- ifelse(dflocal$frisked=="Y",1,0) fit <- rpart(frisked_bin ~ sex + age + weight + height + perstop + city , method="anova", maxdepth=3, cp=.001, data=dflocal) fit  

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required