merge.rFerns: Merge two random ferns models

Description Usage Arguments Value Note Examples

View source: R/tools.R

Description

This function combines two compatible (same decision, same training data structure and same depth) models into a single ensemble. It can be used to distribute model training, perform it on batches of data, save checkouts or precisely investigate its course.

Usage

1
2
3
4
5
6
7
8
9
## S3 method for class 'rFerns'
merge(
  x,
  y,
  dropModel = FALSE,
  ignoreObjectConsistency = FALSE,
  trueY = NULL,
  ...
)

Arguments

x

Object of a class rFerns; a first model to be merged.

y

Object of a class rFerns; a second model to be merged. Can also be NULL, x is immediately returned in that case. Has to have be built on the same kind of training data as x, with the same depth.

dropModel

If TRUE, model structure will be dropped to save size. This disallows prediction using the merged model, but retains importance and OOB approximations.

ignoreObjectConsistency

If TRUE, merge will be done even if both models were built on a different sets of objects. This drops OOB approximations.

trueY

Copy of the training decision, used to re-construct OOB error and confusion matrix. Can be omitted, OOB error and confusion matrix will disappear in that case; ignored when ignoreObjectConsistency is TRUE.

...

Ignored, for S3 gerneric/method consistency.

Value

An object of class rFerns, which is a list with the following components:

model

The merged model in case both x and y had model structures included and dropModel was FALSE. Otherwise NULL.

oobErr

OOB approximation of accuracy, if can be computed. Namely, when oobScores could be and trueY is provided.

importance

The merged importance scores in case both x and y had importance calculated. Shadow importance appears only if both models had it enabled.

oobScores

OOB scores, if can be computed; namely if both models had it calculated and ignoreObjectConsistency was not used.

oobPreds

A vector of OOB predictions of class for each object in training set, if can be computed.

oobConfusionMatrix

OOB confusion matrix, if can be computed. Namely, when oobScores could be and trueY is provided.

timeTaken

Time used to train the model, calculated as a sum of training times of x and y.

parameters

Numerical vector of three elements: classes, depth and ferns.

classLabels

Copy of levels(Y) after purging unused levels.

isStruct

Copy of the train set structure.

merged

Set to TRUE to mark that merging was done.

Note

In case of different training object sets were used to build the merged models, merged importance is calculated but mileage may vary; for substantially different sets it may become biased. Your have been warned.

Shadow importance is only merged when both models have shadow importance and the same consistentSeed value; otherwise shadow importance would be biased down.

The order of objects in x and y is not important; the only exception is merging with NULL, in which case x must be an rFerns object for R to use proper merge method.

Examples

1
2
3
4
5
6
7
8
9
set.seed(77)
#Fetch Iris data
data(iris)
#Build models
rFerns(Species~.,data=iris)->modelA
rFerns(Species~.,data=iris)->modelB
modelAB<-merge(modelA,modelB)
print(modelA)
print(modelAB)

Example output

 Forest of 1000 ferns of a depth 5.

 OOB error 5.33%; OOB confusion matrix:
            True
Predicted    setosa versicolor virginica
  setosa         50          0         0
  versicolor      0         46         4
  virginica       0          4        46

 Forest of 2000 ferns of a depth 5.

rFerns documentation built on Sept. 22, 2021, 5:10 p.m.

Related to merge.rFerns in rFerns...