skmultiflow.meta.AdaptiveRandomForestRegressor

class skmultiflow.meta.AdaptiveRandomForestRegressor(n_estimators=10, max_features='auto', aggregation_method='median', weighted_vote_strategy=None, lambda_value=6, drift_detection_method=ADWIN(delta=0.001), warning_detection_method=ADWIN(delta=0.01), drift_detection_criteria='mse', max_byte_size=1048576000, memory_estimate_period=2000000, grace_period=50, split_confidence=0.01, tie_threshold=0.05, binary_split=False, stop_mem_management=False, remove_poor_atts=False, no_preprune=False, leaf_prediction='perceptron', nominal_attributes=None, learning_ratio_perceptron=0.1, learning_ratio_decay=0.001, learning_ratio_const=True, random_state=None)[source]

Adaptive Random Forest regressor.

Parameters
n_estimators: int, optional (default=10)

Number of trees in the ensemble.

max_featuresint, float, str or None, optional (default=”auto”)
Max number of attributes for each node split.
- If int, then consider max_features features at each split.
- If float, then max_features is a percentage and int(max_features * n_features) features are considered at each split.
- If “auto”, then max_features=sqrt(n_features).
- If “sqrt”, then max_features=sqrt(n_features) (same as “auto”).
- If “log2”, then max_features=log2(n_features).
- If None, then max_features=n_features.
lambda_value: int, optional (default=6)

The lambda value for bagging (lambda=6 corresponds to Leverage Bagging).

aggregation_method: str, optional (default=’median’)
The method to use to aggregate predictions in the ensemble.
- ‘mean’
- ‘median’
weighted_vote_strategy: str or None, optional (default=None)
Metric used to weight individual tree’s responses when aggregating them. Only used when aggregation_method='mean'. Possible values are:
- None: Do not assign weights to individual tree’s predictions. Use the arithmetic mean instead.
- ‘mse’: Weight predictions using trees’ Mean Square Error
- ‘mae’: Weight predictions using trees’ Mean Absolute Error
drift_detection_method: BaseDriftDetector or None, optional (default=ADWIN(0.001))

Drift Detection method. Set to None to disable Drift detection.

warning_detection_method: BaseDriftDetector or None, default(ADWIN(0.01))

Warning Detection method. Set to None to disable warning detection.

drift_detection_criteria: str, optional (default=’mse’)
The criteria used to track drifts.
- ‘mse’ - Mean Square Error
- ‘mae’ - Mean Absolute Error
- ‘predictions’ - predicted target values
max_byte_size: int, optional (default=1048576000)

(ARFHoeffdingTreeRegressor parameter) Maximum memory consumed by the tree.

memory_estimate_period: int, optional (default=2000000)

(ARFHoeffdingTreeRegressor parameter) Number of instances between memory consumption checks.

grace_period: int, optional (default=50)

(ARFHoeffdingTreeRegressor parameter) Number of instances a leaf should observe between split attempts.

split_confidence: float, optional (default=0.01)

(ARFHoeffdingTreeRegressor parameter) Allowed error in split decision, a value closer to 0 takes longer to decide.

tie_threshold: float, optional (default=0.05)

(ARFHoeffdingTreeRegressor parameter) Threshold below which a split will be forced to break ties.

binary_split: bool, optional (default=False)

(ARFHoeffdingTreeRegressor parameter) If True, only allow binary splits.

stop_mem_management: bool, optional (default=False)

(ARFHoeffdingTreeRegressor parameter) If True, stop growing as soon as memory limit is hit.

remove_poor_atts: bool, optional (default=False)

(ARFHoeffdingTreeRegressor parameter) If True, disable poor attributes.

no_preprune: bool, optional (default=False)

(ARFHoeffdingTreeRegressor parameter) If True, disable pre-pruning.

leaf_prediction: str, optional (default=’perceptron’)
(ARFHoeffdingTreeRegressor parameter) Prediction mechanism used at leafs.
- ‘mean’ - Target mean
- ‘perceptron’ - Perceptron
nominal_attributes: list, optional (default=None)

(ARFHoeffdingTreeRegressor parameter) List of Nominal attributes. If emtpy, then assume that all attributes are numerical.

learning_ratio_perceptron: float (default=0.1)

(ARFHoeffdingTreeRegressor parameter) The learning rate of the perceptron.

learning_ratio_decay: float (default=0.001)

(ARFHoeffdingTreeRegressor parameter) Decay multiplier for the learning rate of the perceptron

learning_ratio_const: Bool (default=True)

(ARFHoeffdingTreeRegressor parameter) If False the learning ratio will decay with the number of examples seen.

random_state: int, RandomState instance or None, optional (default=None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random. Used when leaf_prediction is ‘perceptron’.

Notes

The 3 most important aspects of Adaptive Random Forest [1] are: (1) inducing diversity through re-sampling; (2) inducing diversity through randomly selecting subsets of features for node splits (see skmultiflow.trees.arf_hoeffding_tree); (3) drift detectors per base tree, which cause selective resets in response to drifts. It also allows training background trees, which start training if a warning is detected and replace the active tree if the warning escalates to a drift.

Notice that this implementation is slightly different from the original algorithm proposed in [2]. The HoeffdingTreeRegressor is used as base learner, instead of FIMT-DD. It also adds a new strategy to monitor the incoming data and check for concept drifts. The monitored data (either the trees’ errors or their predictions) are centered and scaled (z-score normalization) to have zero mean and unit standard deviation. Transformed values are then again normalized in the [0, 1] range to fulfil ADWIN’s requirements. We assume that the data subjected to the z-score normalization lies within the interval of the mean \(\pm3\sigma\), as it occurs in normal distributions.

References

1

Gomes, H.M., Bifet, A., Read, J., Barddal, J.P., Enembreck, F., Pfharinger, B., Holmes, G. and Abdessalem, T., 2017. Adaptive random forests for evolving data stream classification. Machine Learning, 106(9-10), pp.1469-1495.

2

Gomes, H.M., Barddal, J.P., Boiko, L.E., Bifet, A., 2018. Adaptive random forests for data stream regression. ESANN 2018.

Examples

>>> # Imports
>>> from skmultiflow.data import RegressionGenerator
>>> from skmultiflow.meta import AdaptiveRandomForestRegressor
>>> import numpy as np
>>>
>>> # Setup a data stream
>>> stream = RegressionGenerator(random_state=1, n_samples=200)
>>> # Prepare stream for use
>>>
>>> # Setup the Adaptive Random Forest regressor
>>> arf_reg = AdaptiveRandomForestRegressor(random_state=123456)
>>>
>>> # Auxiliary variables to control loop and track performance
>>> n_samples = 0
>>> max_samples = 200
>>> y_pred = np.zeros(max_samples)
>>> y_true = np.zeros(max_samples)
>>>
>>> # Run test-then-train loop for max_samples and while there is data
>>> while n_samples < max_samples and stream.has_more_samples():
>>>     X, y = stream.next_sample()
>>>     y_true[n_samples] = y[0]
>>>     y_pred[n_samples] = arf_reg.predict(X)[0]
>>>     arf_reg.partial_fit(X, y)
>>>     n_samples += 1
>>>
>>> # Display results
>>> print('Adaptive Random Forest regressor example')
>>> print('{} samples analyzed.'.format(n_samples))
>>> print('Mean absolute error: {}'.format(np.mean(np.abs(y_true - y_pred))))

Methods

fit(self, X, y[, sample_weight])

Fit the model.

get_info(self)

Collects and returns the information about the configuration of the estimator

get_params(self[, deep])

Get parameters for this estimator.

get_votes_for_instance(self, X)

partial_fit(self, X, y[, sample_weight])

Partially (incrementally) fit the model.

predict(self, X)

Predict target values for the passed data.

predict_proba(self, X)

Not implemented for this method.

reset(self)

Reset ARFR.

score(self, X, y[, sample_weight])

Returns the coefficient of determination R^2 of the prediction.

set_params(self, **params)

Set the parameters of this estimator.

fit(self, X, y, sample_weight=None)[source]

Fit the model.

Parameters
Xnumpy.ndarray of shape (n_samples, n_features)

The features to train the model.

y: numpy.ndarray of shape (n_samples, n_targets)

An array-like with the target values of all samples in X.

sample_weight: numpy.ndarray, optional (default=None)

Samples weight. If not provided, uniform weights are assumed. Usage varies depending on the learning method.

Returns
self
get_info(self)[source]

Collects and returns the information about the configuration of the estimator

Returns
string

Configuration of the estimator.

get_params(self, deep=True)[source]

Get parameters for this estimator.

Parameters
deepboolean, optional

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns
paramsmapping of string to any

Parameter names mapped to their values.

partial_fit(self, X, y, sample_weight=None)[source]

Partially (incrementally) fit the model.

Parameters
Xnumpy.ndarray of shape (n_samples, n_features)

The features to train the model.

y: numpy.ndarray of shape (n_samples)

An array-like with the target values of all samples in X.

sample_weight: (default=None)

This parameter it is not used in AdaptiveRandomForestRegressor since the ensemble algorithm internally assign different weights to the incoming instances. Kept for method’s signature compatibility purpose only.

Returns
self
predict(self, X)[source]

Predict target values for the passed data.

Parameters
Xnumpy.ndarray of shape (n_samples, n_features)

The set of data samples for which to predict the target value.

Returns
A numpy.ndarray with all the predictions for the samples in X.
predict_proba(self, X)[source]

Not implemented for this method.

reset(self)[source]

Reset ARFR.

score(self, X, y, sample_weight=None)[source]

Returns the coefficient of determination R^2 of the prediction.

The coefficient R^2 is defined as (1 - u/v), where u is the residual sum of squares ((y_true - y_pred) ** 2).sum() and v is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a R^2 score of 0.0.

Parameters
Xarray-like, shape = (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix instead, shape = (n_samples, n_samples_fitted], where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like, shape = (n_samples) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like, shape = [n_samples], optional

Sample weights.

Returns
scorefloat

R^2 of self.predict(X) wrt. y.

Notes

The R2 score used when calling score on a regressor will use multioutput='uniform_average' from version 0.23 to keep consistent with metrics.r2_score. This will influence the score method of all the multioutput regressors (except for multioutput.MultiOutputRegressor). To specify the default value manually and avoid the warning, please either call metrics.r2_score directly or make a custom scorer with metrics.make_scorer (the built-in scorer 'r2' uses multioutput='uniform_average').

set_params(self, **params)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns
self