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/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 -> 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()
Method 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()
#> V11 V12 V9 V37 V51
#> 2.655917e-02 2.559018e-02 1.096389e-02 7.786247e-03 7.702977e-03
#> V27 V48 V17 V13 V2
#> 6.618910e-03 6.508539e-03 6.035184e-03 5.834251e-03 5.653643e-03
#> V52 V49 V4 V28 V36
#> 5.357714e-03 5.336316e-03 4.856883e-03 4.789241e-03 4.307333e-03
#> V31 V42 V14 V25 V50
#> 4.004979e-03 3.900512e-03 3.426712e-03 2.941080e-03 2.758961e-03
#> V20 V10 V35 V45 V39
#> 2.747624e-03 2.685954e-03 2.627085e-03 2.458533e-03 2.027807e-03
#> V15 V41 V44 V56 V30
#> 2.007980e-03 1.871002e-03 1.846515e-03 1.556590e-03 1.473242e-03
#> V6 V23 V26 V3 V57
#> 1.449826e-03 1.429093e-03 1.331108e-03 1.272696e-03 1.155810e-03
#> V24 V18 V7 V53 V34
#> 1.147531e-03 8.193743e-04 7.043631e-04 6.134349e-04 5.383718e-04
#> V58 V46 V40 V5 V1
#> 4.754960e-04 2.805065e-04 2.434426e-04 1.243555e-04 3.613498e-05
#> V54 V8 V19 V16 V59
#> 2.784567e-05 -9.837356e-08 -2.670665e-04 -2.817015e-04 -3.756060e-04
#> V55 V22 V33 V32 V38
#> -8.051232e-04 -8.358764e-04 -8.975164e-04 -1.117001e-03 -1.426245e-03
#> V21 V43 V29 V47 V60
#> -1.750950e-03 -1.814953e-03 -1.905523e-03 -2.272928e-03 -2.520236e-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
#> 2 R R 0.4642937 0.5357063
#> 9 R R 0.3786746 0.6213254
#> 15 R R 0.3898651 0.6101349
#> --- --- --- --- ---
#> 194 M M 0.7414683 0.2585317
#> 198 M M 0.7319286 0.2680714
#> 199 M M 0.7915397 0.2084603
# Score the predictions
pred$score()
#> classif.ce
#> 0.2318841