Classification Imbalanced Random Forest Src Learner
mlr_learners_classif.imbalanced_rfsrc.Rd
Imbalanced Random forest for classification between two classes.
Calls randomForestSRC::imbalanced.rfsrc()
from from randomForestSRC.
Meta Information
Task type: “classif”
Predict Types: “response”, “prob”
Feature Types: “logical”, “integer”, “numeric”, “factor”, “ordered”
Required Packages: mlr3, randomForestSRC
Parameters
Id | Type | Default | Levels | Range |
ntree | integer | 500 | \([1, \infty)\) | |
method | character | rfq | rfq, brf, standard | - |
block.size | integer | 10 | \([1, \infty)\) | |
fast | logical | FALSE | TRUE, FALSE | - |
ratio | numeric | - | \([0, 1]\) | |
mtry | integer | - | \([1, \infty)\) | |
mtry.ratio | numeric | - | \([0, 1]\) | |
nodesize | integer | 15 | \([1, \infty)\) | |
nodedepth | integer | - | \([1, \infty)\) | |
splitrule | character | gini | gini, auc, entropy | - |
nsplit | integer | 10 | \([0, \infty)\) | |
importance | character | FALSE | FALSE, TRUE, none, permute, random, anti | - |
bootstrap | character | by.root | by.root, by.node, none, by.user | - |
samptype | character | swor | swor, swr | - |
samp | untyped | - | - | |
membership | logical | FALSE | TRUE, FALSE | - |
sampsize | untyped | - | - | |
sampsize.ratio | numeric | - | \([0, 1]\) | |
na.action | character | na.omit | na.omit, na.impute | - |
nimpute | integer | 1 | \([1, \infty)\) | |
ntime | integer | - | \([1, \infty)\) | |
cause | integer | - | \([1, \infty)\) | |
proximity | character | FALSE | FALSE, TRUE, inbag, oob, all | - |
distance | character | FALSE | FALSE, TRUE, inbag, oob, all | - |
forest.wt | character | FALSE | FALSE, TRUE, inbag, oob, all | - |
xvar.wt | untyped | - | - | |
split.wt | untyped | - | - | |
forest | logical | TRUE | TRUE, FALSE | - |
var.used | character | FALSE | FALSE, all.trees, by.tree | - |
split.depth | character | FALSE | FALSE, all.trees, by.tree | - |
seed | integer | - | \((-\infty, -1]\) | |
do.trace | logical | FALSE | TRUE, FALSE | - |
statistics | logical | FALSE | TRUE, FALSE | - |
get.tree | untyped | - | - | |
outcome | character | train | train, test | - |
ptn.count | integer | 0 | \([0, \infty)\) | |
cores | integer | 1 | \([1, \infty)\) | |
save.memory | logical | FALSE | TRUE, FALSE | - |
perf.type | character | - | gmean, misclass, brier, none | - |
case.depth | logical | FALSE | TRUE, FALSE | - |
Custom mlr3 parameters
mtry
: This hyperparameter can alternatively be set via the added hyperparametermtry.ratio
asmtry = max(ceiling(mtry.ratio * n_features), 1)
. Note thatmtry
andmtry.ratio
are mutually exclusive.sampsize
: This hyperparameter can alternatively be set via the added hyperparametersampsize.ratio
assampsize = max(ceiling(sampsize.ratio * n_obs), 1)
. Note thatsampsize
andsampsize.ratio
are mutually exclusive.cores
: This value is set as the optionrf.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
as.data.table(mlr_learners)
for a table of available Learners in the running session (depending on the loaded packages).Chapter in the mlr3book: https://mlr3book.mlr-org.com/basics.html#learners
mlr3learners for a selection of recommended learners.
mlr3cluster for unsupervised clustering learners.
mlr3pipelines to combine learners with pre- and postprocessing steps.
mlr3tuning for tuning of hyperparameters, mlr3tuningspaces for established default tuning spaces.
Super classes
mlr3::Learner
-> mlr3::LearnerClassif
-> LearnerClassifImbalancedRandomForestSRC
Methods
Method importance()
The importance scores are extracted from the slot importance
.
Returns
Named numeric()
.
Examples
# Define the Learner
learner = mlr3::lrn("classif.imbalanced_rfsrc", importance = "TRUE")
print(learner)
#>
#> ── <LearnerClassifImbalancedRandomForestSRC> (classif.imbalanced_rfsrc): Imbalan
#> • Model: -
#> • Parameters: importance=TRUE
#> • Packages: mlr3 and randomForestSRC
#> • Predict Types: [response] and prob
#> • Feature Types: logical, integer, numeric, factor, and ordered
#> • Encapsulation: none (fallback: -)
#> • Properties: importance, missings, oob_error, twoclass, and weights
#> • Other settings: use_weights = 'use'
# Define a Task
task = mlr3::tsk("sonar")
# Create train and test set
ids = mlr3::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: 78, 61
#> Number of trees: 3000
#> Forest terminal node size: 1
#> Average no. of terminal nodes: 16.9687
#> 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.2787
#> (OOB) Brier score: 0.13554242
#> (OOB) Normalized Brier score: 0.54216969
#> (OOB) AUC: 0.92622951
#> (OOB) Log-loss: 0.43079573
#> (OOB) PR-AUC: 0.91159034
#> (OOB) G-mean: 0.82558398
#> (OOB) Requested performance error: 0.17441602
#>
#> Confusion matrix:
#>
#> predicted
#> observed M R class.error
#> M 69 9 0.1154
#> R 14 47 0.2295
#>
#> (OOB) Misclassification rate: 0.1654676
print(learner$importance())
#> V46 V12 V45 V49 V44 V14
#> 0.041521417 0.026782858 0.026782858 0.023631756 0.017756570 0.014770137
#> V29 V4 V48 V1 V13 V15
#> 0.014770137 0.014770137 0.014770137 0.008830029 0.008830029 0.008830029
#> V18 V21 V25 V28 V54 V55
#> 0.008830029 0.008830029 0.008830029 0.008830029 0.008830029 0.008830029
#> V57 V9 V37 V47 V11 V17
#> 0.008830029 0.008830029 0.006004327 0.006004327 0.002932812 0.002932812
#> V19 V27 V39 V43 V51 V56
#> 0.002932812 0.002932812 0.002932812 0.002932812 0.002932812 0.002932812
#> V16 V22 V23 V32 V34 V35
#> 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
#> V40 V42 V5 V50 V53 V60
#> 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
#> V36 V26 V31 V10 V2 V24
#> -0.002668715 -0.002922430 -0.005075879 -0.005960973 -0.005960973 -0.005960973
#> V3 V38 V59 V7 V8 V20
#> -0.005960973 -0.005960973 -0.005960973 -0.005960973 -0.005960973 -0.008736582
#> V30 V41 V52 V58 V33 V6
#> -0.008736582 -0.008736582 -0.008736582 -0.008736582 -0.011879517 -0.014760635
# Make predictions for the test rows
predictions = learner$predict(task, row_ids = ids$test)
# Score the predictions
predictions$score()
#> classif.ce
#> 0.07246377