merge.literanger {literanger}R Documentation

Merge two random forests

Description

Copy the trees from two forests to construct a new random forest object.

Usage

## S3 method for class 'literanger'
merge(x, y, save_memory = FALSE, verbose = FALSE, ...)

Arguments

x

A trained random forest literanger object.

y

A trained random forest literanger object.

save_memory

Ignored, only used in training (perhaps future use).

verbose

Print additional debug output from merging procedure.

...

Ignored.

Details

This is a naive implementation of a random-forest merge procedure. The trees from each forest are copied and then used to construct a new random forest object.

Classification and regression forests cannot be mixed together. The response type and levels (if a factor) must match.

The predictor names, type, and levels (if a factor) must match, although they can be provided in a different order.

There is no requirement that the forests were trained on the same data; just the same data types.

Internally, literanger will 'map' any differences in the order of the predictors (or its internal representation of response values) between x and y so that the result has the same ordering as x.

The out-of-bag error is discarded, along with the training information, as the result is a merged forest (not a trained one). It is up to you, the user, to keep track of the training parameters of x and y if they are still of use to you.

Value

Object of class literanger with a copy of the trees from x and y held in the cpp11_ptr item, and the following items:

tree_type

The type of tree in the forest, either 'classification' or 'regression'.

n_tree

The sum of the number of trees in x and y.

training

An empty list; as the result is due to merging, not training.

predictors

A list with the names of the predictors, the names of the unordered predictors, and the levels of any factors.

response

The levels and type indicator (e.g. logical, factor, etc) of the response.

oob_error

NULL, as there is no consensus on how to merge OOB estimates

cpp11_ptr

An external pointer to the merged forest. DO NOT MODIFY.

Author(s)

stephematician stephematician@gmail.com.

Examples

## Train two classification forests
train_idx <- sample(nrow(iris), 2/3 * nrow(iris))
iris_train <- iris[train_idx, ]
iris_test <- iris[-train_idx, ]
lr_x <- train(data=iris_train, response_name="Species", n_tree=32)
lr_y <- train(data=iris_train, response_name="Species", n_tree=32)

## Merge
lr_iris <- merge(lr_x, lr_y)
pred_iris <- predict(lr_iris, newdata=iris_test)
table(iris_test$Species, pred_iris$values)


[Package literanger version 0.2.0 Index]