DecisionTree-class | R Documentation |
DecisionTree objects comprising random forest models generated with RandForest
.
## S3 method for class 'DecisionTree'
as.dendrogram(object, ...)
## S3 method for class 'DecisionTree'
plot(x, plotGain=FALSE, ...)
object |
an object of class |
x |
an object of class |
plotGain |
logical; should the Gini gain or decrease in sum of squared error be plotted for each decision point of the tree? |
... |
For For |
These methods help work with DecisionTree
objects, which are returned as part of RandForest
. Coercion to dendrogram
objects creates a 'dendrogram'
corresponding to the structure of the decision tree. Each internal node possesses the standard attributes present in a 'dendrogram'
object, along with the following extra attributes:
variable
: which variable was used to split at this node.
thresh
: cutoff for partitioning points; values less than thresh
are assigned to the left node, and those greater than to the right node.
gain
: change in the metric to maximize. For classification trees this is the Gini Gain, and for regression trees this is the decrease in sum of squared error.
Plotting allows for extra arguments to be passed to plot
and text
. Arguments prefixed with 'text'
are passed to text
, which controls the labeling of internal nodes. Common arguments used here are text.cex
, text.adj
, text.srt
, and text.col
. All other arguments are passed to plot.dendrogram
. For example, col='blue'
would change the dendrogram color to blue, whereas text.col='blue'
would change the interior node labels to blue (but not the dendrogram itself).
as.dendrogram
returns an object of class 'dendrogram'
. plot
returns NULL
invisibly.
These functions can be quite slow for large decision trees. Usage is discouraged for trees with more than 100 internal nodes.
Aidan Lakshman ahl27@pitt.edu
RandForest
set.seed(199L)
n_samp <- 100L
AA <- rnorm(n_samp, mean=1, sd=5)
BB <- rnorm(n_samp, mean=2, sd=3)
CC <- rgamma(n_samp, shape=1, rate=2)
err <- rnorm(n_samp, sd=0.5)
y <- AA + BB + 2*CC + err
d <- data.frame(AA,BB,CC,y)
train_i <- 1:90
test_i <- 91:100
train_data <- d[train_i,]
test_data <- d[test_i,]
rf_regr <- RandForest(y~., data=train_data, rf.mode="regression", max_depth=5L)
if(interactive()){
# Visualize one of the decision trees
plot(rf_regr[[1]])
}
dend <- as.dendrogram(rf_regr[[1]])
plot(dend)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.