BlockForest Classification Learner
Source:R/learner_blockForest_classif_blockforest.R
mlr_learners_classif.blockforest.RdRandom forests for blocks of clinical and omics covariate data.
Calls blockForest::blockfor() from package blockForest.
In this learner, only the trained forest object ($forest) is retained. The
optimized block-specific tuning parameters (paramvalues) and the biased OOB
error estimate (biased_oob_error_donotuse) are discarded, as they are either
not needed for downstream use or not reliable for performance estimation.
Initial parameter values
num.threadsis initialized to 1 to avoid conflicts with parallelization via future.
Meta Information
Task type: “classif”
Predict Types: “response”, “prob”
Feature Types: “logical”, “integer”, “numeric”, “factor”, “ordered”
Required Packages: mlr3, mlr3extralearners, blockForest
Parameters
| Id | Type | Default | Levels | Range |
| blocks | untyped | - | - | |
| block.method | character | BlockForest | BlockForest, RandomBlock, BlockVarSel, VarProb, SplitWeights | - |
| num.trees | integer | 2000 | \([1, \infty)\) | |
| mtry | untyped | NULL | - | |
| nsets | integer | 300 | \([1, \infty)\) | |
| num.trees.pre | integer | 1500 | \([1, \infty)\) | |
| splitrule | character | extratrees | extratrees, gini | - |
| always.select.block | integer | 0 | \([0, 1]\) | |
| importance | character | - | none, impurity, impurity_corrected, permutation | - |
| num.threads | integer | - | \([1, \infty)\) | |
| seed | integer | NULL | \((-\infty, \infty)\) | |
| verbose | logical | TRUE | TRUE, FALSE | - |
References
Hornung, R., Wright, N. M (2019). “Block Forests: Random forests for blocks of clinical and omics covariate data.” BMC Bioinformatics, 20(1), 1–17. doi:10.1186/s12859-019-2942-y . https://doi.org/10.1186/s12859-019-2942-y.
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/chapters/chapter2/data_and_basic_modeling.html#sec-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 -> LearnerClassifBlockForest
Methods
Inherited methods
mlr3::Learner$base_learner()mlr3::Learner$configure()mlr3::Learner$encapsulate()mlr3::Learner$format()mlr3::Learner$help()mlr3::Learner$predict()mlr3::Learner$predict_newdata()mlr3::Learner$print()mlr3::Learner$reset()mlr3::Learner$selected_features()mlr3::Learner$train()mlr3::LearnerClassif$predict_newdata_fast()
LearnerClassifBlockForest$importance()
The importance scores are extracted from the model slot variable.importance.
Returns
Named numeric().
Examples
# Define a Task
task = tsk("sonar")
# Create train and test set
ids = partition(task)
# check task's features
task$feature_names
#> [1] "V1" "V10" "V11" "V12" "V13" "V14" "V15" "V16" "V17" "V18" "V19" "V2"
#> [13] "V20" "V21" "V22" "V23" "V24" "V25" "V26" "V27" "V28" "V29" "V3" "V30"
#> [25] "V31" "V32" "V33" "V34" "V35" "V36" "V37" "V38" "V39" "V4" "V40" "V41"
#> [37] "V42" "V43" "V44" "V45" "V46" "V47" "V48" "V49" "V5" "V50" "V51" "V52"
#> [49] "V53" "V54" "V55" "V56" "V57" "V58" "V59" "V6" "V60" "V7" "V8" "V9"
# partition features to 2 blocks
blocks = list(bl1 = 1:42, bl2 = 43:60)
# define learner
learner = lrn("classif.blockforest", blocks = blocks,
importance = "permutation", nsets = 10, predict_type = "prob",
num.trees = 50, num.trees.pre = 10, splitrule = "gini")
# Train the learner on the training ids
learner$train(task, row_ids = ids$train)
# feature importance
learner$importance()
#> V52 V12 V48 V11 V13
#> 1.916367e-02 1.694346e-02 1.469702e-02 1.209255e-02 1.089444e-02
#> V9 V10 V36 V21 V37
#> 8.634044e-03 7.915608e-03 7.317123e-03 6.299934e-03 5.675076e-03
#> V4 V28 V49 V22 V45
#> 5.576666e-03 5.551177e-03 5.482009e-03 5.294685e-03 4.963355e-03
#> V35 V20 V23 V18 V5
#> 4.425969e-03 4.324405e-03 3.953076e-03 3.748461e-03 3.465156e-03
#> V1 V46 V44 V57 V43
#> 3.231064e-03 3.140697e-03 3.096348e-03 2.926055e-03 2.900139e-03
#> V59 V40 V17 V16 V26
#> 2.799892e-03 2.336726e-03 2.254521e-03 2.007475e-03 1.684886e-03
#> V19 V29 V39 V15 V60
#> 1.601244e-03 1.512705e-03 1.509220e-03 1.415036e-03 1.376031e-03
#> V30 V34 V41 V25 V14
#> 1.147607e-03 1.033488e-03 9.361383e-04 7.558608e-04 4.136232e-04
#> V54 V58 V50 V38 V33
#> 3.915810e-04 3.475905e-04 3.333728e-04 3.252212e-04 2.904181e-04
#> V42 V2 V31 V56 V47
#> 1.508350e-04 1.247016e-04 -8.821469e-05 -1.960042e-04 -6.122093e-04
#> V24 V53 V6 V32 V27
#> -7.963861e-04 -9.801814e-04 -9.953586e-04 -1.043678e-03 -1.525431e-03
#> V7 V3 V51 V8 V55
#> -1.542857e-03 -1.627514e-03 -1.859758e-03 -3.281666e-03 -3.813409e-03
# Make predictions for the test observations
pred = learner$predict(task, row_ids = ids$test)
pred
#>
#> ── <PredictionClassif> for 69 observations: ────────────────────────────────────
#> row_ids truth response prob.M prob.R
#> 3 R M 0.6570000 0.3430000
#> 4 R R 0.4610794 0.5389206
#> 8 R M 0.6734683 0.3265317
#> --- --- --- --- ---
#> 199 M M 0.8797619 0.1202381
#> 204 M M 0.8774444 0.1225556
#> 205 M M 0.6544683 0.3455317
# Score the predictions
pred$score()
#> classif.ce
#> 0.1449275