maxframe.learn.ensemble.RandomForestRegressor#
- class maxframe.learn.ensemble.RandomForestRegressor(*, n_estimators=100, criterion='squared_error', max_depth=None, max_bins=32, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=1.0, bootstrap=True, oob_score=False, random_state=None, verbose=0, max_samples=None, max_memory_in_mb=256, feature_subset_strategy='auto')[source]#
A distributed random forest regressor.
A random forest is a meta estimator that fits a number of decision tree regressors on various sub-samples of the dataset and uses averaging to improve the predictive accuracy and control over-fitting.
This distributed implementation trains all trees simultaneously using a single pass over the data per tree level, which is significantly more efficient than training trees independently.
- Parameters:
n_estimators (int, default=100) – The number of trees in the forest.
criterion ({"squared_error"}, default="squared_error") – The function to measure the quality of a split. Only “squared_error” is currently supported in the distributed implementation.
max_depth (int, default=None) – The maximum depth of the tree. If None, then nodes are expanded until all leaves contain less than min_samples_split samples.
max_bins (int, default=32) – The maximum number of bins used to discretize continuous features. See
DecisionTreeClassifierfor details.min_samples_split (int or float, default=2) – The minimum number of samples required to split an internal node.
min_samples_leaf (int or float, default=1) – The minimum number of samples required to be at a leaf node.
min_weight_fraction_leaf (float, default=0.0) – The minimum weighted fraction of the sum total of weights required to be at a leaf node.
max_features ({"sqrt", "log2"}, int or float, default=1.0) –
The number of features to consider when looking for the best split.
If int, then consider max_features features at each split.
If float, then max_features is a fraction and max(1, int(max_features * n_features)) features are considered.
If “sqrt”, then max_features=sqrt(n_features).
If “log2”, then max_features=log2(n_features).
If 1.0, then max_features=n_features.
Note
The default of 1.0 is equivalent to bagged trees and more randomness can be achieved by setting smaller values, e.g. 0.3.
bootstrap (bool, default=True) – Whether bootstrap samples are used when building trees. If False, the whole dataset is used to build each tree.
oob_score (bool, default=False) –
Whether to use out-of-bag samples to estimate the generalization score.
Warning
Out-of-bag scoring is not yet implemented. Setting
oob_score=Truewill raiseNotImplementedError.random_state (int, RandomState instance or None, default=None) – Controls both the randomness of the bootstrapping of the samples and the sampling of the features to consider at each node.
verbose (int, default=0) – Controls the verbosity when fitting and predicting.
max_samples (int or float, default=None) – If bootstrap is True, the number of samples to draw from X to train each base estimator.
max_memory_in_mb (int, default=256) – The maximum memory in MB for aggregating statistics per node group.
feature_subset_strategy ({"auto", "sqrt", "log2", "onethird", "all"} or int, default="auto") – The strategy for selecting features at each node split. Default “auto” resolves to “onethird” for regression.
- estimator_#
The child estimator template.
- Type:
- estimators_#
The collection of fitted sub-estimators.
- Type:
- feature_importances_#
The impurity-based feature importances. Currently returns all zeros (not yet implemented). Tracked as a known limitation.
- Type:
ndarray of shape (n_features,)
- feature_names_in_#
Names of features seen during fit.
- Type:
ndarray of shape (n_features_in_,)
- oob_score_#
Score of the training dataset obtained using an out-of-bag estimate. Only when
oob_scoreis True.- Type:
- oob_prediction_#
Prediction computed with out-of-bag estimate on the training set. Only when
oob_scoreis True.- Type:
ndarray of shape (n_samples,)
See also
DecisionTreeRegressorA distributed decision tree regressor.
RandomForestClassifierA distributed random forest classifier.
Notes
Limitations compared to scikit-learn
In addition to the limitations documented in
DecisionTreeClassifierandRandomForestClassifier:Only “squared_error” criterion is supported. “absolute_error”, “friedman_mse”, and “poisson” are not yet available.
The default
max_featuresis 1.0 (all features), which differs from sklearn’s original recommendation of n_features/3 [1] but aligns with more recent empirical findings [2].
References
Examples
>>> from maxframe.learn.ensemble import RandomForestRegressor >>> reg = RandomForestRegressor(n_estimators=100, max_depth=5) >>> reg.fit(X_train, y_train) RandomForestRegressor(max_depth=5, n_estimators=100) >>> predictions = reg.predict(X_test)
- __init__(*, n_estimators=100, criterion='squared_error', max_depth=None, max_bins=32, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=1.0, bootstrap=True, oob_score=False, random_state=None, verbose=0, max_samples=None, max_memory_in_mb=256, feature_subset_strategy='auto')[source]#
Methods
__init__(*[, n_estimators, criterion, ...])execute([session, run_kwargs, extra_tileables])fetch([session, run_kwargs])fit(X, y[, sample_weight, execute, session, ...])Fit a distributed random forest regressor.
predict(X[, execute, session, run_kwargs])Predict regression target for X.
score(X, y[, sample_weight])Return the coefficient of determination \(R^2\) of the prediction.