Skip to content

AdaptiveRandomForestClassifier

Adaptive Random Forest classifier.

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

  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.

Parameters

  • n_models (int) – defaults to 10

    Number of trees in the ensemble.

  • max_features (Union[bool, str, int]) – defaults to sqrt

    Max number of attributes for each node split.
    - If int, then consider max_features at each split.
    - If float, then max_features is a percentage and int(max_features * n_features) features are considered per split.
    - If "sqrt", then max_features=sqrt(n_features).
    - If "log2", then max_features=log2(n_features).
    - If None, then max_features=n_features.

  • lambda_value (int) – defaults to 6

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

  • metric (river.metrics.base.MultiClassMetric) – defaults to Accuracy: 0.00%

    Metric used to track trees performance within the ensemble.

  • disable_weighted_vote – defaults to False

    If True, disables the weighted vote prediction.

  • drift_detector (Union[base.DriftDetector, NoneType]) – defaults to ADWIN

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

  • warning_detector (Union[base.DriftDetector, NoneType]) – defaults to ADWIN

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

  • grace_period (int) – defaults to 50

    [Tree parameter] Number of instances a leaf should observe between split attempts.

  • max_depth (int) – defaults to None

    [Tree parameter] The maximum depth a tree can reach. If None, the tree will grow indefinitely.

  • split_criterion (str) – defaults to info_gain

    [Tree parameter] Split criterion to use.
    - 'gini' - Gini
    - 'info_gain' - Information Gain
    - 'hellinger' - Hellinger Distance

  • split_confidence (float) – defaults to 0.01

    [Tree parameter] Allowed error in split decision, a value closer to 0 takes longer to decide.

  • tie_threshold (float) – defaults to 0.05

    [Tree parameter] Threshold below which a split will be forced to break ties.

  • leaf_prediction (str) – defaults to nba

    [Tree parameter] Prediction mechanism used at leafs.
    - 'mc' - Majority Class
    - 'nb' - Naive Bayes
    - 'nba' - Naive Bayes Adaptive

  • nb_threshold (int) – defaults to 0

    [Tree parameter] Number of instances a leaf should observe before allowing Naive Bayes.

  • nominal_attributes (list) – defaults to None

    [Tree parameter] List of Nominal attributes. If empty, then assume that all attributes are numerical.

  • splitter (river.tree.splitter.base.Splitter) – defaults to None

    [Tree parameter] The Splitter or Attribute Observer (AO) used to monitor the class statistics of numeric features and perform splits. Splitters are available in the tree.splitter module. Different splitters are available for classification and regression tasks. Classification and regression splitters can be distinguished by their property is_target_class. This is an advanced option. Special care must be taken when choosing different splitters. By default, tree.splitter.GaussianSplitter is used if splitter is None.

  • binary_split (bool) – defaults to False

    [Tree parameter] If True, only allow binary splits.

  • max_size (int) – defaults to 32

    [Tree parameter] Maximum memory (MB) consumed by the tree.

  • memory_estimate_period (int) – defaults to 2000000

    [Tree parameter] Number of instances between memory consumption checks.

  • stop_mem_management (bool) – defaults to False

    [Tree parameter] If True, stop growing as soon as memory limit is hit.

  • remove_poor_attrs (bool) – defaults to False

    [Tree parameter] If True, disable poor attributes to reduce memory usage.

  • merit_preprune (bool) – defaults to True

    [Tree parameter] If True, enable merit-based tree pre-pruning.

  • seed (int) – defaults to None

    Random seed for reproducibility.

Attributes

  • models

Examples

>>> from river import ensemble
>>> from river import evaluate
>>> from river import metrics
>>> from river import synth

>>> dataset = synth.ConceptDriftStream(seed=42, position=500,
...                                    width=40).take(1000)

>>> model = ensemble.AdaptiveRandomForestClassifier(seed=8, leaf_prediction="mc")

>>> metric = metrics.Accuracy()

>>> evaluate.progressive_val_score(dataset, model, metric)
Accuracy: 76.68%

Methods

append

S.append(value) -- append value to the end of the sequence

Parameters

  • item
clear

S.clear() -> None -- remove all items from S

clone

Return a fresh estimator with the same parameters.

The clone has the same parameters but has not been updated with any data. This works by looking at the parameters from the class signature. Each parameter is either - recursively cloned if it's a River classes. - deep-copied via copy.deepcopy if not. If the calling object is stochastic (i.e. it accepts a seed parameter) and has not been seeded, then the clone will not be idempotent. Indeed, this method's purpose if simply to return a new instance with the same input parameters.

copy
count

S.count(value) -> integer -- return number of occurrences of value

Parameters

  • item
extend

S.extend(iterable) -- extend sequence by appending elements from the iterable

Parameters

  • other
index

S.index(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

Parameters

  • item
  • args
insert

S.insert(index, value) -- insert value before index

Parameters

  • i
  • item
learn_one
pop

S.pop([index]) -> item -- remove and return item at index (default last). Raise IndexError if list is empty or index is out of range.

Parameters

  • i – defaults to -1
predict_one

Predict the label of a set of features x.

Parameters

  • x (dict)

Returns

typing.Union[bool, str, int]: The predicted label.

predict_proba_one

Predict the probability of each label for a dictionary of features x.

Parameters

  • x (dict)

Returns

typing.Dict[typing.Union[bool, str, int], float]: A dictionary that associates a probability which each label.

remove

S.remove(value) -- remove first occurrence of value. Raise ValueError if the value is not present.

Parameters

  • item
reverse

S.reverse() -- reverse IN PLACE

sort

References


  1. Heitor Murilo Gomes, Albert Bifet, Jesse Read, Jean Paul Barddal, Fabricio Enembreck, Bernhard Pfharinger, Geoff Holmes, Talel Abdessalem. Adaptive random forests for evolving data stream classification. In Machine Learning, DOI: 10.1007/s10994-017-5642-8, Springer, 2017.