stabletree-coercion: Coercion Functions

stabletree-coercionR Documentation

Coercion Functions

Description

Functions coercing various forest objects to objects of class "stabletree".

Usage

  as.stabletree(x, ...)
  ## S3 method for class 'randomForest'
as.stabletree(x, applyfun = NULL, cores = NULL, ...)
  ## S3 method for class 'RandomForest'
as.stabletree(x, applyfun = NULL, cores = NULL, ...)
  ## S3 method for class 'cforest'
as.stabletree(x, applyfun = NULL, cores = NULL, savetrees = FALSE, ...)
  ## S3 method for class 'ranger'
as.stabletree(x, applyfun = NULL, cores = NULL, ...)

Arguments

x

an object of class randomForest, RandomForest-class, cforest, or ranger.

applyfun

a lapply-like function. The default is to use lapply unless cores is specified in which case mclapply is used (for multicore computations on platforms that support these).

cores

integer. The number of cores to use in multicore computations using mclapply (see above).

savetrees

logical. If TRUE, trees of the forests are returned.

...

additional arguments (currently not used).

Details

Random forests fitted using randomForest, cforest, cforest or ranger are coerced to "stabletree" objects.

Note that when plotting a randomForest or ranger, the gray areas of levels of a nominal variable do not mimic exactly the same behavior as for classical "stabletree" objects, due to randomForest and ranger, not storing any information whether any individuals were left fulfilling the splitting criterion in the subsample. Therefore, gray areas only indicate that this level of this variable has already been used in a split before in such a way that it could not be used for any further splits.

For ranger, interaction terms are (currently) not supported.

Value

as.stabletree returns an object of class "stabletree" which is a list with the following components:

call

the call from the model object x,

B

the number of trees of the random forest,

sampler

the random forest fitting function,

vs0

numeric vector of the variable selections of the original tree, here always a vector of zeros because there is no original tree,

br0

always NULL (only included for consistency),

vs

numeric matrix of the variable selections for each tree of the random forest,

br

list of the break points (only the breaks for each variable over all trees of the random forest,

classes

character vector indicating the classes of all partitioning variables,

trees

a list of tree objects of class "party", or NULL.

See Also

stabletree, plot.stabletree

Examples



## build a randomForest using randomForest
library(randomForest)
set.seed(1)
rf <- randomForest(Species ~ ., data = iris)

## coerce to a stabletree
srf <- as.stabletree(rf)
print(srf)
summary(srf, original = FALSE) # there is no original tree
barplot(srf)
image(srf)
plot(srf)

## build a RandomForest using party
library("party")
set.seed(2)
cf_party <- cforest(Species ~ ., data = iris,
  control = cforest_unbiased(mtry = 2))

## coerce to a stabletree
scf_party <- as.stabletree(cf_party)
print(scf_party)
summary(scf_party, original = FALSE)
barplot(scf_party)
image(scf_party)
plot(scf_party)

## build a cforest using partykit
library("partykit")
set.seed(3)
cf_partykit <- cforest(Species ~ ., data = iris)

## coerce to a stabletree
scf_partykit <- as.stabletree(cf_partykit)
print(scf_partykit)
summary(scf_partykit, original = FALSE)
barplot(scf_partykit)
image(scf_partykit)
plot(scf_partykit)

## build a random forest using ranger
library("ranger")
set.seed(4)
rf_ranger <- ranger(Species ~ ., data = iris)

## coerce to a stabletree
srf_ranger <- as.stabletree(rf_ranger)
print(srf_ranger)
summary(srf_ranger, original = FALSE)
barplot(srf_ranger)
image(srf_ranger)
plot(srf_ranger)



stablelearner documentation built on April 14, 2023, 12:40 a.m.