Skip to main content

RandomForestRegressor

A bagged ensemble of regression trees whose predictions are averaged. Trades a small bias increase for a large variance reduction relative to a single deep tree.

Algorithm

Identical bootstrap + feature-subspace scheme as the classifier, but each tree minimises squared error and the ensemble prediction is the mean of the per-tree outputs.

Constructor

Skigen::RandomForestRegressor<Scalar> model(int n_estimators = 100, CriterionReg = MSE, std::optional<int> max_depth = nullopt, ...);

Parameters

ParameterDefaultDescription
n_estimators100Number of trees.
max_featuresOneThirdCandidate features per split.
bootstraptrueSample with replacement per tree.
oob_scorefalseExpose an out-of-bag R² estimate.
n_jobs1Trees fitted in parallel.
random_statenulloptSeed.

Methods

MethodDescription
fit(X, y)Grow the forest.
predict(X)Mean of per-tree predictions.
score(X, y)R² coefficient of determination.

Fitted Attributes

AccessorDescription
feature_importances()Mean impurity decrease per feature.
oob_score()Out-of-bag R² (when enabled).

Example

Skigen::RandomForestRegressor<double> rf(100);
rf.fit(X, y);
auto preds = rf.predict(X_test);
Verified against scikit-learn

This estimator is checked by the parity suite. See the generator tests/parity/generate_ensemble_reference.py and the reference fixtures in tests/parity/data/random_forest_regressor/, exercised by tests/parity/parity_ensemble.cpp.

API Reference

For full signatures see the RandomForestRegressor API Reference.