Skip to contents

Random forest for classification. Calls randomForestSRC::rfsrc() from randomForestSRC.

Dictionary

This Learner can be instantiated via lrn():

lrn("classif.rfsrc")

Meta Information

  • Task type: “classif”

  • Predict Types: “response”, “prob”

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

  • Required Packages: mlr3, mlr3extralearners, randomForestSRC

Parameters

IdTypeDefaultLevelsRange
ntreeinteger500\([1, \infty)\)
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-
block.sizeinteger10\([1, \infty)\)
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)\)
causeinteger-\([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, by.tree-
split.depthcharacterFALSEFALSE, all.trees, by.tree-
seedinteger-\((-\infty, -1]\)
do.tracelogicalFALSETRUE, FALSE-
statisticslogicalFALSETRUE, FALSE-
get.treeuntyped--
outcomecharactertraintrain, test-
ptn.countinteger0\([0, \infty)\)
coresinteger1\([1, \infty)\)
save.memorylogicalFALSETRUE, FALSE-
perf.typecharacter-gmean, misclass, brier, none-
case.depthlogicalFALSETRUE, FALSE-

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

Breiman, Leo (2001). “Random Forests.” Machine Learning, 45(1), 5–32. ISSN 1573-0565, doi:10.1023/A:1010933404324 .

See also

Author

RaphaelS1

Super classes

mlr3::Learner -> mlr3::LearnerClassif -> LearnerClassifRandomForestSRC

Methods

Inherited methods


Method new()

Creates a new instance of this R6 class.


Method importance()

The importance scores are extracted from the model slot importance, returned for 'all'.

Usage

LearnerClassifRandomForestSRC$importance()

Returns

Named numeric().


Method selected_features()

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

Usage

LearnerClassifRandomForestSRC$selected_features()

Returns

character().


Method oob_error()

OOB error extracted from the model slot err.rate.

Usage

LearnerClassifRandomForestSRC$oob_error()

Returns

numeric().


Method clone()

The objects of this class are cloneable with this method.

Usage

LearnerClassifRandomForestSRC$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# Define the Learner
learner = mlr3::lrn("classif.rfsrc", importance = "TRUE")
print(learner)
#> <LearnerClassifRandomForestSRC:classif.rfsrc>: Random Forest
#> * Model: -
#> * Parameters: importance=TRUE
#> * Packages: mlr3, mlr3extralearners, randomForestSRC
#> * Predict Types:  [response], prob
#> * Feature Types: logical, integer, numeric, factor
#> * Properties: importance, missings, multiclass, oob_error, twoclass,
#>   weights

# 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: 79, 60
#>                      Number of trees: 500
#>            Forest terminal node size: 1
#>        Average no. of terminal nodes: 17.036
#> 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: RF-C
#>                               Family: class
#>                       Splitting rule: gini *random*
#>        Number of random split points: 10
#>                     Imbalanced ratio: 1.3167
#>                    (OOB) Brier score: 0.13909445
#>         (OOB) Normalized Brier score: 0.55637781
#>                            (OOB) AUC: 0.90675105
#>                       (OOB) Log-loss: 0.4397445
#>                         (OOB) PR-AUC: 0.89172607
#>                         (OOB) G-mean: 0.76500462
#>    (OOB) Requested performance error: 0.20143885, 0.07594937, 0.36666667
#> 
#> Confusion matrix:
#> 
#>           predicted
#>   observed  M  R class.error
#>          M 73  6      0.0759
#>          R 23 37      0.3833
#> 
#>       (OOB) Misclassification rate: 0.2086331
print(learner$importance())
#>         V12         V11          V9         V10         V15         V17 
#> 0.090199504 0.088119489 0.039425083 0.035211694 0.028761377 0.028267568 
#>         V16         V47         V13         V37         V20         V18 
#> 0.025746098 0.022851377 0.022684402 0.019795267 0.018156382 0.017785716 
#>         V30          V5         V36         V21         V45         V46 
#> 0.017774668 0.017003839 0.016960646 0.016844490 0.016674119 0.016290888 
#>         V28         V44         V34         V48          V4         V31 
#> 0.015987090 0.015705140 0.015284203 0.013216961 0.012926999 0.012606540 
#>         V52         V49         V19         V32         V58         V27 
#> 0.012210962 0.012052375 0.011230826 0.010898342 0.010486633 0.010149728 
#>         V55         V33         V40         V14         V51         V43 
#> 0.009573193 0.009006317 0.008892834 0.008890082 0.008759174 0.008618228 
#>          V6          V7         V39         V29         V59         V35 
#> 0.008476087 0.007846166 0.007411371 0.006827816 0.006752593 0.006537264 
#>         V24         V26         V54          V8         V60         V53 
#> 0.006154788 0.005971975 0.005855054 0.005796551 0.005562026 0.005401991 
#>         V38          V3         V42         V23         V56          V2 
#> 0.005055749 0.004658122 0.004538896 0.004515481 0.004497277 0.004221224 
#>         V50         V22          V1         V41         V57         V25 
#> 0.004219231 0.003781026 0.003626499 0.002637587 0.001752013 0.001015705 

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

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