Regression Random Planted Forest Learner
Source:R/learner_randomPlantedForest_regr_rpf.R
mlr_learners_regr.rpf.RdRandom planted forest: a directly interpretable tree ensemble.
Calls randomPlantedForest::rpf() from package 'randomPlantedForest'.
Meta Information
Task type: “regr”
Predict Types: “response”
Feature Types: “logical”, “integer”, “numeric”, “factor”, “ordered”
Required Packages: mlr3, mlr3extralearners, randomPlantedForest
Parameters
| Id | Type | Default | Levels | Range |
| max_interaction | integer | 2 | \([0, \infty)\) | |
| max_interaction_ratio | numeric | - | \([0, 1]\) | |
| max_interaction_limit | integer | - | \([1, \infty)\) | |
| ntrees | integer | 50 | \([1, \infty)\) | |
| splits | integer | 30 | \([1, \infty)\) | |
| split_structure | character | leaves | leaves, hist, cur_trees_1, cur_trees_2, res_trees | - |
| split_try | integer | 10 | \([1, \infty)\) | |
| t_try | numeric | 0.4 | \([0, 1]\) | |
| max_candidates | integer | 50 | \([1, \infty)\) | |
| split_decay_rate | numeric | 0.1 | \([0, \infty)\) | |
| delete_leaves | logical | TRUE | TRUE, FALSE | - |
| purify | logical | FALSE | TRUE, FALSE | - |
| nthreads | integer | 1 | \([1, \infty)\) | |
| export_forest | logical | FALSE | TRUE, FALSE | - |
| deterministic | logical | FALSE | TRUE, FALSE | - |
| marshal_include_data | logical | FALSE | TRUE, FALSE | - |
Installation
Package 'randomPlantedForest' is not on CRAN and has to be installed from GitHub via
remotes::install_github("PlantedML/randomPlantedForest").
Saving a Learner
The fitted forest lives in C++ memory and does not survive R serialization.
Call $marshal() before writing a trained learner to disk, and $unmarshal() after loading it again.
By default, marshaling does not store the training data, so a restored model cannot be purified afterwards.
Set purify = TRUE at training time if purification is needed, or include the training data in the marshaled
model via the marshal_include_data parameter or $marshal(include_data = TRUE).
Custom mlr3 parameters
max_interaction:This hyperparameter can alternatively be set via
max_interaction_ratioasmax_interaction = max(ceiling(max_interaction_ratio * n_features), 1). The parametermax_interaction_limitcan optionally be set as an upper bound, such thatmax_interaction_ratio * min(n_features, max_interaction_limit)is used instead. This is analogous tomtry.ratioinclassif.ranger, withmax_interaction_limitas an additional constraint. The parametermax_interaction_limitis initialized toInf.
marshal_include_data:Whether to store the training data when marshaling the model, which is required to call
randomPlantedForest::purify()on a restored model. Defaults toFALSEto keep marshaled models small. Can be overridden for a single call via$marshal(include_data = TRUE).
References
Hiabu, Munir, Mammen, Enno, Meyer, T. J (2023). “Random Planted Forest: a directly interpretable tree ensemble.” arXiv preprint arXiv:2012.14563. doi:10.48550/ARXIV.2012.14563 .
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::LearnerRegr -> LearnerRegrRandomPlantedForest
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::LearnerRegr$predict_newdata_fast()
LearnerRegrRandomPlantedForest$marshal()
Marshal the learner's model.
Arguments
...(any)
Additional arguments passed tomlr3::marshal_model().
LearnerRegrRandomPlantedForest$unmarshal()
Unmarshal the learner's model.
Arguments
...(any)
Additional arguments passed tomlr3::unmarshal_model().
Examples
# Define the Learner
learner = lrn("regr.rpf")
print(learner)
#>
#> ── <LearnerRegrRandomPlantedForest> (regr.rpf): Random Planted Forest ──────────
#> • Model: -
#> • Parameters: max_interaction_limit=Inf
#> • Packages: mlr3, mlr3extralearners, and randomPlantedForest
#> • Predict Types: [response]
#> • Feature Types: logical, integer, numeric, factor, and ordered
#> • Encapsulation: none (fallback: -)
#> • Properties: marshal
#> • Other settings: use_weights = 'error', predict_raw = 'FALSE'
# Define a Task
task = tsk("mtcars")
# Create train and test set
ids = partition(task)
# Train the learner on the training ids
learner$train(task, row_ids = ids$train)
print(learner$model)
#> ── Regression Random Planted Forest ────────────────────────────────────────────
#> Predictors: `am`, `carb`, `cyl`, …, `vs`, and `wt`
#> 50 tree families with 30 splits each on 10 predictors, interactions to degree
#> 2.
#> ℹ Forest is not purified.
#>
#> ── Tree growing
#> split_structure: leaves
#> split_try: 10
#> t_try: 0.4
#> max_candidates: 50
#> split_decay_rate: 0.1
#> delete_leaves: TRUE
#>
#> ℹ Fit using 1 thread, also the default for `predict()` and `purify()`.
# Make predictions for the test rows
predictions = learner$predict(task, row_ids = ids$test)
# Score the predictions
predictions$score()
#> regr.mse
#> 7.91502