Skip to contents

Imbalanced Random forest for classification between two classes. Calls randomForestSRC::imbalanced.rfsrc() from from randomForestSRC.

Dictionary

This Learner can be instantiated via lrn():

lrn("classif.imbalanced_rfsrc")

Meta Information

  • Task type: “classif”

  • Predict Types: “response”, “prob”

  • Feature Types: “logical”, “integer”, “numeric”, “factor”, “ordered”

  • Required Packages: mlr3, mlr3extralearners, randomForestSRC

Parameters

IdTypeDefaultLevelsRange
ntreeinteger500\([1, \infty)\)
methodcharacterrfqrfq, brf, standard-
block.sizeinteger10\([1, \infty)\)
fastlogicalFALSETRUE, FALSE-
rationumeric-\([0, 1]\)
mtryinteger-\([1, \infty)\)
mtry.rationumeric-\([0, 1]\)
nodesizeinteger15\([1, \infty)\)
nodedepthinteger-\([1, \infty)\)
splitrulecharacterginigini, auc, entropy-
nsplitinteger10\([0, \infty)\)
importancecharacterFALSEFALSE, TRUE, none, permute, random, anti-
bootstrapcharacterby.rootby.root, by.node, none, by.user-
samptypecharactersworswor, swr-
sampuntyped--
membershiplogicalFALSETRUE, FALSE-
sampsizeuntyped--
sampsize.rationumeric-\([0, 1]\)
na.actioncharacterna.omitna.omit, na.impute-
nimputeinteger1\([1, \infty)\)
ntimeinteger-\([1, \infty)\)
proximitycharacterFALSEFALSE, TRUE, inbag, oob, all-
distancecharacterFALSEFALSE, TRUE, inbag, oob, all-
forest.wtcharacterFALSEFALSE, TRUE, inbag, oob, all-
xvar.wtuntyped--
split.wtuntyped--
forestlogicalTRUETRUE, FALSE-
var.usedcharacterFALSEFALSE, all.trees-
split.depthcharacterFALSEFALSE, all.trees-
seedinteger-\((-\infty, -1]\)
do.tracelogicalFALSETRUE, FALSE-
get.treeuntyped--
outcomecharactertraintrain, test-
ptn.countinteger0\([0, \infty)\)
coresinteger1\([1, \infty)\)
save.memorylogicalFALSETRUE, FALSE-
perf.typecharacter-gmean, misclass, brier, none-
case.depthlogicalFALSETRUE, FALSE-
marginal.xvaruntypedNULL-

Custom mlr3 parameters

  • mtry: This hyperparameter can alternatively be set via the added hyperparameter mtry.ratio as mtry = max(ceiling(mtry.ratio * n_features), 1). Note that mtry and mtry.ratio are mutually exclusive.

  • sampsize: This hyperparameter can alternatively be set via the added hyperparameter sampsize.ratio as sampsize = max(ceiling(sampsize.ratio * n_obs), 1). Note that sampsize and sampsize.ratio are mutually exclusive.

  • cores: This value is set as the option rf.cores during training and is set to 1 by default.

References

O’Brien R, Ishwaran H (2019). “A random forests quantile classifier for class imbalanced data.” Pattern Recognition, 90, 232–249. doi:10.1016/j.patcog.2019.01.036 .

Chao C, Leo B (2004). “Using Random Forest to Learn Imbalanced Data.” University of California, Berkeley.

See also

Author

HarutyunyanLiana

Super classes

mlr3::Learner -> mlr3::LearnerClassif -> LearnerClassifImbalancedRandomForestSRC

Methods

Inherited methods


LearnerClassifImbalancedRandomForestSRC$new()

Creates a new instance of this R6 class.


LearnerClassifImbalancedRandomForestSRC$importance()

The importance scores are extracted from the slot importance.

Usage

LearnerClassifImbalancedRandomForestSRC$importance()

Returns

Named numeric().


LearnerClassifImbalancedRandomForestSRC$selected_features()

Selected features are extracted from the model slot var.used.

Note: Due to a known issue in randomForestSRC, enabling var.used = "all.trees" causes prediction to fail. Therefore, this setting should be used exclusively for feature selection purposes and not when prediction is required.

Usage

LearnerClassifImbalancedRandomForestSRC$selected_features()

Returns

character().


LearnerClassifImbalancedRandomForestSRC$oob_error()

OOB error extracted from the model slot err.rate.

Usage

LearnerClassifImbalancedRandomForestSRC$oob_error()

Returns

numeric().


LearnerClassifImbalancedRandomForestSRC$clone()

The objects of this class are cloneable with this method.

Usage

LearnerClassifImbalancedRandomForestSRC$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# Define the Learner
learner = lrn("classif.imbalanced_rfsrc", importance = "TRUE")
print(learner)
#> 
#> ── <LearnerClassifImbalancedRandomForestSRC> (classif.imbalanced_rfsrc): Imbalan
#> • Model: -
#> • Parameters: importance=TRUE
#> • Packages: mlr3, mlr3extralearners, and randomForestSRC
#> • Predict Types: [response] and prob
#> • Feature Types: logical, integer, numeric, factor, and ordered
#> • Encapsulation: none (fallback: -)
#> • Properties: importance, missings, oob_error, selected_features, twoclass, and
#> weights
#> • Other settings: use_weights = 'use', predict_raw = 'FALSE'

# Define a Task
task = tsk("sonar")
# Create train and test set
ids = partition(task)

# Train the learner on the training ids
learner$train(task, row_ids = ids$train)

print(learner$model)
#>                          Sample size: 139
#>            Frequency of class labels: M=72, R=67
#>                      Number of trees: 3000
#>            Forest terminal node size: 1
#>        Average no. of terminal nodes: 16.693
#> No. of variables tried at each split: 8
#>               Total no. of variables: 60
#>        Resampling used to grow trees: swor
#>     Resample size used to grow trees: 88
#>                             Analysis: RFQ
#>                               Family: class
#>                       Splitting rule: auc *random*
#>        Number of random split points: 10
#>                     Imbalanced ratio: 1.0746
#>                    (OOB) Brier score: 0.12580115
#>         (OOB) Normalized Brier score: 0.50320461
#>                            (OOB) AUC: 0.94465174
#>                       (OOB) Log-loss: 0.41197839
#>                         (OOB) PR-AUC: 0.94659311
#>                         (OOB) G-mean: 0.88050566
#>    (OOB) Requested performance error: 0.50320461, 0.25160231, 0.25160231
#> 
#> Confusion matrix:
#> 
#>           predicted
#>   observed  M  R class.error class.freq
#>          M 68  4      0.0556         72
#>          R 12 55      0.1791         67
#> 
#>       (OOB) Misclassification rate: 0.1151079
#> 
#> Random-classifier baselines (uniform):
#>    Brier: 0.25   Normalized Brier: 1   Log-loss: 0.69314718   PR-AUC: 0.48201439
print(learner$importance())
#>          V12          V11          V23          V21           V9          V51 
#> 0.1555311593 0.0986379442 0.0620242833 0.0547478785 0.0512358818 0.0468665809 
#>          V52          V48          V36          V49          V45          V16 
#> 0.0468639866 0.0422420946 0.0370459455 0.0365392876 0.0326742721 0.0287517851 
#>          V27          V20          V10          V22          V17          V43 
#> 0.0283621405 0.0253884168 0.0245875338 0.0236355583 0.0228636908 0.0225596784 
#>          V37          V31          V15          V46          V26          V28 
#> 0.0206825510 0.0192488566 0.0186743754 0.0140492582 0.0136128439 0.0133423200 
#>          V24          V47          V44          V13          V25          V39 
#> 0.0130494472 0.0127973567 0.0124101650 0.0122476719 0.0121789878 0.0109187951 
#>          V18          V59          V14          V35           V5          V58 
#> 0.0106513536 0.0097963795 0.0093531448 0.0090090137 0.0087983973 0.0087708079 
#>           V4          V19          V38          V55           V8          V32 
#> 0.0080383442 0.0080212257 0.0079230001 0.0073481468 0.0071827572 0.0063052548 
#>          V29           V2           V6          V60           V3          V50 
#> 0.0061360623 0.0058584135 0.0056824391 0.0051365678 0.0045906959 0.0044061703 
#>          V33          V57          V42          V41          V40          V34 
#> 0.0041768539 0.0040520109 0.0036350881 0.0036006633 0.0035634566 0.0035179546 
#>           V1          V30          V54          V53          V56           V7 
#> 0.0031537273 0.0027050037 0.0023926530 0.0017272197 0.0006047496 0.0004443049 

# Make predictions for the test rows
predictions = learner$predict(task, row_ids = ids$test)

# Score the predictions
predictions$score()
#> classif.ce 
#>   0.173913