stabletree-coercion {stablelearner} | R Documentation |
Functions coercing various forest objects to objects of class
"stabletree"
.
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, ...)
x |
an object of class |
applyfun |
a |
cores |
integer. The number of cores to use in multicore computations
using |
savetrees |
logical. If |
... |
additional arguments (currently not used). |
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.
as.stabletree
returns an object of class "stabletree"
which is a
list with the following components:
call |
the call from the model object |
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 |
vs |
numeric matrix of the variable selections for each tree of the random forest, |
br |
list of the break points (only the |
classes |
character vector indicating the classes of all partitioning variables, |
trees |
a list of tree objects of class |
## 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)