7) Visualising a C5 Decision Tree.

This Blog entry is from the Probability and Trees section in Learn R.

To visualise a C5 Decision tree, the plot() function from the R base functions can be used, passing the C5 decision tree model as the argument:

plot(C50Tree)
1.png

Run the line of script to console:

2.png

It can be seen that a visualisation has been written out to the plots pane:

3.png

If the tree is very large, then the zoom feature will need to be used to ensure that the plot fits the screen.  Even with zoon, it is possibly more appropriate to communicate the product of C5 decision trees as a list of rules, as covered in Blog entries that follow).

2) Visualise a rpart Decision Tree

This Blog entry is from the Probability and Trees section in Learn R.

Once familiar with the output of a regression tree, it becomes an informative means to create business rules. Quite often however, for the purposes of communication, it is more satisfying to create a visualisation.  A package called rpart.plot is available for the purposes of translating regression trees to a visualisation.  Start by installing the rpart.plot package:

1.png

Click install to download and install the package:

2.png

Reference the library:

library(rpart.plot)
3.png

Run the line of script to console:

4.png

To transpose the Regression Tree to a plot, simply pass it as an argument to the rpart.plot() function:

rpart.plot(RegressionTree)
5.png

Run the line of script to console:

6.png

It can be seen that a complex visualisation has been created in the plots window of R Studio:

7.png

The visualisation is exceptionally hard to interpret for a large regression tree; hence it will likely need to be exported to a PDF or Image file to use a zoom function:

8.png