Regression Random Forest Learner
Source:R/learner_randomForest_regr_randomForest.R
mlr_learners_regr.randomForest.RdRandom forest for regression.
Calls randomForest::randomForest() from randomForest.
Meta Information
Task type: “regr”
Predict Types: “response”
Feature Types: “logical”, “integer”, “numeric”, “factor”, “ordered”
Required Packages: mlr3, mlr3extralearners, randomForest
Parameters
| Id | Type | Default | Levels | Range |
| ntree | integer | 500 | \([1, \infty)\) | |
| mtry | integer | - | \([1, \infty)\) | |
| replace | logical | TRUE | TRUE, FALSE | - |
| strata | untyped | - | - | |
| sampsize | untyped | - | - | |
| nodesize | integer | 5 | \([1, \infty)\) | |
| maxnodes | integer | - | \([1, \infty)\) | |
| importance | character | FALSE | mse, nudepurity, none | - |
| localImp | logical | FALSE | TRUE, FALSE | - |
| proximity | logical | FALSE | TRUE, FALSE | - |
| oob.prox | logical | - | TRUE, FALSE | - |
| norm.votes | logical | TRUE | TRUE, FALSE | - |
| do.trace | logical | FALSE | TRUE, FALSE | - |
| keep.forest | logical | TRUE | TRUE, FALSE | - |
| keep.inbag | logical | FALSE | TRUE, FALSE | - |
| predict.all | logical | FALSE | TRUE, FALSE | - |
| nodes | logical | FALSE | TRUE, FALSE | - |
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::LearnerRegr -> LearnerRegrRandomForest
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()
Method importance()
The importance scores are extracted from the slot importance.
Parameter 'importance' must be set to either "mse" or "nodepurity".
Returns
Named numeric().
Examples
# Define the Learner
learner = lrn("regr.randomForest", importance = "mse")
print(learner)
#>
#> ── <LearnerRegrRandomForest> (regr.randomForest): Random Forest ────────────────
#> • Model: -
#> • Parameters: importance=mse
#> • Packages: mlr3, mlr3extralearners, and randomForest
#> • Predict Types: [response]
#> • Feature Types: logical, integer, numeric, factor, and ordered
#> • Encapsulation: none (fallback: -)
#> • Properties: importance, oob_error, and weights
#> • Other settings: use_weights = 'use'
# 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)
#>
#> Call:
#> randomForest(formula = formula, data = data, importance = TRUE)
#> Type of random forest: regression
#> Number of trees: 500
#> No. of variables tried at each split: 3
#>
#> Mean of squared residuals: 6.981456
#> % Var explained: 76.16
print(learner$importance())
#> cyl wt disp hp drat carb
#> 10.39727983 6.45805257 5.36734985 4.28626098 1.00799135 0.93465315
#> am gear vs qsec
#> 0.31355107 0.21469539 0.21383646 0.08618109
# Make predictions for the test rows
predictions = learner$predict(task, row_ids = ids$test)
# Score the predictions
predictions$score()
#> regr.mse
#> 9.96543