Conversion of a CoreModel tree into a rpart.object

Share:

Description

The function converts a given CoreModel model (decision or regression tree) into a rpart.object prepared for visualization with plot function.

Usage

1
  getRpartModel(model, dataset)

Arguments

model

A tree model produced by CoreModel

dataset

A data set which was used in learning of the model.

Details

The conversion creates rpart.object and copies CORElearn internal structures contained in memory controlled by dynamic link library written in C++.

An alternative visualization is accessible via function display, which outputs tree structure formatted for screen or in dot format.

Value

Function returns a rpart.object.

Author(s)

Initial version by John Adeyanju Alao, improvements by Marko Robnik-Sikonja.

See Also

CoreModel, plot.CoreModel,rpart.object, display

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# plot a decision tree directly
dataset <- CO2
md<-CoreModel(Plant ~ ., dataset, model="tree")
plot(md, dataset)

# or indirectly 
rpm <- getRpartModel(md, dataset)
# set angle to tan(0.5)=45 (degrees) and length of branches at least 5 
plot(rpm, branch=0.5, minbranch=5, compress=TRUE)
# pretty=0 prints full names of attributes, 
# numbers to 3 decimals, try to make a dendrogram more compact
text(rpm, pretty=0, digits=3)
destroyModels(md) # clean up

# an alternative is to use fancier rpart.plot package
# rpart.plot(rpm) # rpart.plot has many parameters controlling the output
# but it cannot plot models in tree leaves 

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.