Classification Random Forest SRC Learner
mlr_learners_classif.rfsrc.Rd
Random forest for classification.
Calls randomForestSRC::rfsrc()
from randomForestSRC.
Meta Information
Task type: “classif”
Predict Types: “response”, “prob”
Feature Types: “logical”, “integer”, “numeric”, “factor”
Required Packages: mlr3, mlr3extralearners, randomForestSRC
Parameters
Id | Type | Default | Levels | Range |
ntree | integer | 500 | \([1, \infty)\) | |
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 | - |
block.size | integer | 10 | \([1, \infty)\) | |
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
Breiman, Leo (2001). “Random Forests.” Machine Learning, 45(1), 5–32. ISSN 1573-0565, doi:10.1023/A:1010933404324 .
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
-> LearnerClassifRandomForestSRC
Methods
Method importance()
The importance scores are extracted from the model slot importance
, returned for
'all'.
Returns
Named numeric()
.
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.016
#> 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.1375532
#> (OOB) Normalized Brier score: 0.55021279
#> (OOB) AUC: 0.910625
#> (OOB) Log-loss: 0.43369224
#> (OOB) PR-AUC: 0.91112395
#> (OOB) G-mean: 0.7975222
#> (OOB) Requested performance error: 0.17985612, 0.05333333, 0.328125
#>
#> Confusion matrix:
#>
#> predicted
#> observed M R class.error
#> M 71 4 0.0533
#> R 21 43 0.3281
#>
#> (OOB) Misclassification rate: 0.1798561
print(learner$importance())
#> V11 V12 V48 V10 V47
#> 0.0514086437 0.0499845149 0.0425217687 0.0344019881 0.0319643173
#> V36 V21 V9 V52 V37
#> 0.0261188299 0.0242453260 0.0216488948 0.0216024516 0.0209368419
#> V20 V45 V49 V13 V46
#> 0.0208929311 0.0207595501 0.0206102791 0.0158125688 0.0155132085
#> V39 V17 V30 V44 V51
#> 0.0146776729 0.0142237353 0.0134897609 0.0128069497 0.0123439119
#> V42 V6 V18 V34 V31
#> 0.0109143507 0.0104297974 0.0100079405 0.0095867586 0.0094492540
#> V5 V4 V33 V23 V29
#> 0.0094408057 0.0087015910 0.0086758541 0.0085671636 0.0084310078
#> V16 V22 V32 V8 V50
#> 0.0081141331 0.0078147234 0.0075545403 0.0074432365 0.0072844444
#> V15 V58 V35 V19 V38
#> 0.0071366237 0.0066679704 0.0065545475 0.0062492270 0.0062363925
#> V14 V40 V28 V26 V27
#> 0.0061125015 0.0060967537 0.0058076632 0.0055157546 0.0050845640
#> V7 V3 V59 V57 V24
#> 0.0050730192 0.0049540146 0.0044886416 0.0044000220 0.0043712993
#> V53 V54 V41 V43 V55
#> 0.0040509018 0.0038326657 0.0036528857 0.0036505106 0.0023018194
#> V1 V25 V2 V56 V60
#> 0.0021748914 0.0020355038 0.0002740162 -0.0001291986 -0.0011598225
# Make predictions for the test rows
predictions = learner$predict(task, row_ids = ids$test)
# Score the predictions
predictions$score()
#> classif.ce
#> 0.1884058