API Reference / capymoa /

ensemble.py

CapyMOA ensemble wrappers.

Incremental, mostly drift-aware ensembles backed by CapyMOA/MOA. Registered under capymoa. hub keys, mirroring the native TuiML ensemble family.

Classes

AdaptiveRandomForest

class capymoa.ensemble.AdaptiveRandomForest(_CapyMOAStreamMixin, Classifier)

Adaptive Random Forest drift-aware classifier (hub key capymoa.AdaptiveRandomForest).

Wraps AdaptiveRandomForestClassifier. An ensemble of Hoeffding Trees trained with online bagging and per-tree random feature subsets; each member carries a drift detector and is replaced by a background tree when its accuracy degrades.
Constructor
__init__(
    self,
    ensemble_size: int = 10,
)

Parameters

ensemble_size
int = 10
Number of trees in the forest. More trees improve accuracy at the cost of memory and per-instance training time.

Attributes

schema_
capymoa.stream.Schema
Stream schema derived from the training data.
learner_
capymoa.classifier.AdaptiveRandomForestClassifier
The fitted backing CapyMOA learner.

Notes

Requires the optional CapyMOA extra: pip install 'tuiml[capymoa]'. The strongest general-purpose choice among the CapyMOA classifiers wrapped here, especially under concept drift.
python
>>> from tuiml.capymoa import AdaptiveRandomForest
>>> from tuiml.datasets.generators import Hyperplane
>>> data = Hyperplane(n_samples=1000, n_drift_features=2,
...                   random_state=42).generate()
>>> model = AdaptiveRandomForest(ensemble_size=5).fit(data.X, data.y)
>>> model.predict(data.X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.

OnlineBagging

class capymoa.ensemble.OnlineBagging(_CapyMOAStreamMixin, Classifier)

Online Bagging (Oza & Russell) ensemble classifier (hub key capymoa.OnlineBagging).

Wraps OnlineBagging. Simulates bootstrap sampling on a stream by training each ensemble member on every instance k times, with k \sim \text{Poisson}(1).
Constructor
__init__(
    self,
    ensemble_size: int = 10,
)

Parameters

ensemble_size
int = 10
Number of base learners in the ensemble.

Attributes

schema_
capymoa.stream.Schema
Stream schema derived from the training data.
learner_
capymoa.classifier.OnlineBagging
The fitted backing CapyMOA learner.

Notes

Requires the optional CapyMOA extra: pip install 'tuiml[capymoa]'. No built-in drift handling; for drifting streams prefer LeveragingBagging or AdaptiveRandomForest.
python
>>> from tuiml.capymoa import OnlineBagging
>>> from tuiml.datasets.generators import Agrawal
>>> data = Agrawal(n_samples=1000, function=1, random_state=42).generate()
>>> model = OnlineBagging(ensemble_size=5).fit(data.X, data.y)
>>> model.predict(data.X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.

LeveragingBagging

class capymoa.ensemble.LeveragingBagging(_CapyMOAStreamMixin, Classifier)

Leveraging Bagging drift-aware ensemble classifier (hub key capymoa.LeveragingBagging).

Wraps LeveragingBagging. Extends online bagging with higher resampling weights (\text{Poisson}(6)) for more input diversity, plus ADWIN drift detection that resets underperforming ensemble members.
Constructor
__init__(
    self,
    ensemble_size: int = 10,
)

Parameters

ensemble_size
int = 10
Number of base learners in the ensemble.

Attributes

schema_
capymoa.stream.Schema
Stream schema derived from the training data.
learner_
capymoa.classifier.LeveragingBagging
The fitted backing CapyMOA learner.

Notes

Requires the optional CapyMOA extra: pip install 'tuiml[capymoa]'.
python
>>> from tuiml.capymoa import LeveragingBagging
>>> from tuiml.datasets.generators import Hyperplane
>>> data = Hyperplane(n_samples=1000, n_drift_features=2,
...                   random_state=42).generate()
>>> model = LeveragingBagging(ensemble_size=5).fit(data.X, data.y)
>>> model.predict(data.X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.

AdaptiveRandomForestRegressor

class capymoa.ensemble.AdaptiveRandomForestRegressor(_CapyMOAStreamMixin, Regressor)

Adaptive Random Forest drift-aware regressor (hub key capymoa.AdaptiveRandomForestRegressor).

Wraps AdaptiveRandomForestRegressor. The regression counterpart of the Adaptive Random Forest: an ensemble of FIMT-DD trees with online bagging, random feature subsets, and per-member drift detection.
Constructor
__init__(
    self,
    ensemble_size: int = 10,
)

Parameters

ensemble_size
int = 10
Number of trees in the forest.

Attributes

schema_
capymoa.stream.Schema
Stream schema derived from the training data.
learner_
capymoa.regressor.AdaptiveRandomForestRegressor
The fitted backing CapyMOA learner.

Notes

Requires the optional CapyMOA extra: pip install 'tuiml[capymoa]'.
python
>>> from tuiml.capymoa import AdaptiveRandomForestRegressor
>>> from tuiml.datasets.generators import Friedman
>>> data = Friedman(n_samples=1000, random_state=42).generate()
>>> model = AdaptiveRandomForestRegressor(ensemble_size=5).fit(data.X, data.y)
>>> model.predict(data.X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.