Classification H2O Random Forest Learner
Source:R/learner_h2o_classif_randomForest.R
mlr_learners_classif.h2o.randomForest.RdClassification random forest learner.
Calls h2o::h2o.randomForest() from package h2o.
H2O Connection
If no running H2O connection is found, the learner will automatically start a local H2O server
on 127.0.0.1 via h2o::h2o.init().
If you want to connect to a remote H2O cluster, call h2o::h2o.init() with the appropriate
arguments before training or predicting.
Meta Information
Task type: “classif”
Predict Types: “response”, “prob”
Feature Types: “integer”, “numeric”, “factor”
Required Packages: mlr3, mlr3extralearners, h2o
Parameters
| Id | Type | Default | Levels | Range |
| auc_type | character | AUTO | AUTO, NONE, MACRO_OVR, WEIGHTED_OVR, MACRO_OVO, WEIGHTED_OVO | - |
| balance_classes | logical | FALSE | TRUE, FALSE | - |
| binomial_double_trees | logical | FALSE | TRUE, FALSE | - |
| build_tree_one_node | logical | FALSE | TRUE, FALSE | - |
| categorical_encoding | character | AUTO | AUTO, Enum, OneHotInternal, OneHotExplicit, Binary, Eigen, LabelEncoder, SortByResponse, EnumLimited | - |
| check_constant_response | logical | TRUE | TRUE, FALSE | - |
| checkpoint | untyped | NULL | - | |
| class_sampling_factors | untyped | NULL | - | |
| col_sample_rate_change_per_level | numeric | 1 | \([0, 2]\) | |
| col_sample_rate_per_tree | numeric | 1 | \([0, 1]\) | |
| export_checkpoints_dir | untyped | NULL | - | |
| gainslift_bins | integer | -1 | \([-1, \infty)\) | |
| histogram_type | character | AUTO | AUTO, UniformAdaptive, Random, QuantilesGlobal, RoundRobin, UniformRobust | - |
| ignore_const_cols | logical | TRUE | TRUE, FALSE | - |
| max_after_balance_size | numeric | 5 | \([0, \infty)\) | |
| max_depth | integer | 20 | \([0, \infty)\) | |
| max_runtime_secs | numeric | 0 | \([0, \infty)\) | |
| min_rows | numeric | 1 | \([1, \infty)\) | |
| min_split_improvement | numeric | 1e-05 | \([0, \infty)\) | |
| mtries | integer | -1 | \([1, \infty)\) | |
| nbins | integer | 20 | \([1, \infty)\) | |
| nbins_cats | integer | 1024 | \([1, \infty)\) | |
| nbins_top_level | integer | 1024 | \([1, \infty)\) | |
| ntrees | integer | 50 | \([1, \infty)\) | |
| sample_rate | numeric | 0.632 | \([0, 1]\) | |
| sample_rate_per_class | untyped | NULL | - | |
| score_each_iteration | logical | FALSE | TRUE, FALSE | - |
| score_tree_interval | integer | 0 | \([0, \infty)\) | |
| seed | integer | -1 | \((-\infty, \infty)\) | |
| stopping_metric | character | AUTO | AUTO, logloss, AUC, AUCPR, lift_top_group, misclassification, mean_per_class_error | - |
| stopping_rounds | integer | 0 | \([0, \infty)\) | |
| stopping_tolerance | numeric | 0.001 | \([0, \infty)\) | |
| verbose | logical | FALSE | TRUE, FALSE | - |
References
Fryda T, LeDell E, Gill N, Aiello S, Fu A, Candel A, Click C, Kraljevic T, Nykodym T, Aboyoun P, Kurka M, Malohlava M, Poirier S, Wong W (2025). h2o: R Interface for the 'H2O' Scalable Machine Learning Platform. R package version 3.46.0.9, https://github.com/h2oai/h2o-3.
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 -> LearnerClassifH2ORandomForest
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()
Examples
# Define the Learner
learner = lrn("classif.h2o.randomForest")
print(learner)
#>
#> ── <LearnerClassifH2ORandomForest> (classif.h2o.randomForest): H2O Random Forest
#> • Model: -
#> • Parameters: list()
#> • Packages: mlr3, mlr3extralearners, and h2o
#> • Predict Types: [response] and prob
#> • Feature Types: integer, numeric, and factor
#> • Encapsulation: none (fallback: -)
#> • Properties: missings, multiclass, twoclass, and weights
#> • Other settings: use_weights = 'use', predict_raw = 'FALSE'
# Define a Task
task = tsk("sonar")
# 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)
#> Model Details:
#> ==============
#>
#> H2OBinomialModel: drf
#> Model ID: DRF_model_R_1776854555489_58
#> Model Summary:
#> number_of_trees number_of_internal_trees model_size_in_bytes min_depth
#> 1 50 50 13089 5
#> max_depth mean_depth min_leaves max_leaves mean_leaves
#> 1 9 6.40000 11 21 16.26000
#>
#>
#> H2OBinomialMetrics: drf
#> ** Reported on training data. **
#> ** Metrics reported on Out-Of-Bag training samples **
#>
#> MSE: 0.1314151
#> RMSE: 0.3625123
#> LogLoss: 0.4163646
#> Mean Per-Class Error: 0.1635338
#> AUC: 0.9214703
#> AUCPR: 0.9065756
#> Gini: 0.8429407
#> R^2: 0.4697009
#>
#> Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
#> M R Error Rate
#> M 62 14 0.184211 =14/76
#> R 9 54 0.142857 =9/63
#> Totals 71 68 0.165468 =23/139
#>
#> Maximum Metrics: Maximum metrics at their respective thresholds
#> metric threshold value idx
#> 1 max f1 0.461538 0.824427 43
#> 2 max f2 0.350000 0.910405 60
#> 3 max f0point5 0.571429 0.872340 28
#> 4 max accuracy 0.533333 0.848921 35
#> 5 max precision 1.000000 1.000000 0
#> 6 max recall 0.350000 1.000000 60
#> 7 max specificity 1.000000 1.000000 0
#> 8 max absolute_mcc 0.533333 0.699809 35
#> 9 max min_per_class_accuracy 0.470588 0.828947 41
#> 10 max mean_per_class_accuracy 0.533333 0.840121 35
#> 11 max tns 1.000000 76.000000 0
#> 12 max fns 1.000000 60.000000 0
#> 13 max fps 0.000000 76.000000 86
#> 14 max tps 0.350000 63.000000 60
#> 15 max tnr 1.000000 1.000000 0
#> 16 max fnr 1.000000 0.952381 0
#> 17 max fpr 0.000000 1.000000 86
#> 18 max tpr 0.350000 1.000000 60
#>
#> Gains/Lift Table: Extract with `h2o.gainsLift(<model>, <data>)` or `h2o.gainsLift(<model>, valid=<T/F>, xval=<T/F>)`
#>
#>
# Make predictions for the test rows
predictions = learner$predict(task, row_ids = ids$test)
# Score the predictions
predictions$score()
#> classif.ce
#> 0.1449275