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: 75, 64
#>                      Number of trees: 500
#>            Forest terminal node size: 1
#>        Average no. of terminal nodes: 17.296
#> 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.1719
#>                    (OOB) Brier score: 0.13843574
#>         (OOB) Normalized Brier score: 0.55374296
#>                            (OOB) AUC: 0.9140625
#>                       (OOB) Log-loss: 0.44033095
#>                         (OOB) PR-AUC: 0.90454586
#>                         (OOB) G-mean: 0.77325071
#>    (OOB) Requested performance error: 0.20143885, 0.06666667, 0.359375
#> 
#> Confusion matrix:
#> 
#>           predicted
#>   observed  M  R class.error
#>          M 70  5      0.0667
#>          R 23 41      0.3594
#> 
#>       (OOB) Misclassification rate: 0.2014388
print(learner$importance())
#>          V12          V11          V52          V39           V9          V45 
#> 0.0992211995 0.0634239028 0.0562007124 0.0366942928 0.0345611663 0.0263170945 
#>          V37          V10          V36          V20           V4           V5 
#> 0.0253063850 0.0215177989 0.0196548806 0.0166010294 0.0164865828 0.0164398287 
#>          V33          V27          V51          V46          V48          V15 
#> 0.0157676203 0.0157565299 0.0148772106 0.0147477010 0.0140280853 0.0139569879 
#>          V16          V29           V6          V47          V28          V21 
#> 0.0135477997 0.0122346899 0.0116427927 0.0111869016 0.0109420899 0.0109371108 
#>          V49          V31          V22          V19          V17          V13 
#> 0.0107896978 0.0105112479 0.0104838787 0.0104816517 0.0104553421 0.0103473082 
#>          V40          V18          V30          V32          V53          V35 
#> 0.0102900374 0.0100916173 0.0090388497 0.0081683690 0.0078921576 0.0076877244 
#>          V43          V54          V59          V24          V14           V8 
#> 0.0074490832 0.0073969931 0.0072710355 0.0069926613 0.0064450301 0.0062566334 
#>          V26          V50          V60          V41          V44          V23 
#> 0.0062554033 0.0056818865 0.0052549456 0.0052524872 0.0050875056 0.0049403233 
#>          V34           V3           V7           V1          V25          V57 
#> 0.0039821050 0.0038286375 0.0037999304 0.0037924942 0.0033643700 0.0024830103 
#>          V56          V42          V55           V2          V58          V38 
#> 0.0021930946 0.0018863307 0.0012053167 0.0010081902 0.0008609440 0.0004497023 

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

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