Implementation:Online ml River Base Estimator
| Knowledge Sources | |
|---|---|
| Domains | Online_Learning, Base_Classes |
| Last Updated | 2026-02-08 16:00 GMT |
Overview
The Estimator class is an abstract base class that extends Base and serves as the foundation for all learning algorithms in River.
Description
The Estimator class provides the common interface and functionality for all machine learning models in River, including classifiers, regressors, transformers, and clusterers. It extends the Base class with estimator-specific capabilities such as pipeline composition through operator overloading (| operator), HTML representation for Jupyter notebooks, a tagging system to specify input capabilities, and unit testing infrastructure. The class defines properties like _supervised to indicate whether the estimator requires target values during learning, and _tags to specify what types of inputs (text, categorical, etc.) the estimator can handle.
Usage
Use Estimator as a parent class when creating new learning algorithms in River. It should typically be combined with more specific interfaces like Classifier, Regressor, or Transformer that define the concrete learning and prediction methods. Do not instantiate Estimator directly as it is an abstract base class.
Code Reference
Source Location
- Repository: Online_ml_River
- File: river/base/estimator.py
Signature
class Estimator(base.Base, abc.ABC):
"""An estimator."""
@property
def _supervised(self) -> bool
def __or__(self, other: Estimator | compose.Pipeline) -> compose.Pipeline
def __ror__(self, other: Estimator | compose.Pipeline) -> compose.Pipeline
def _repr_html_(self) -> str
def _more_tags(self) -> set[str]
@property
def _tags(self) -> set[str]
@classmethod
def _unit_test_params(self) -> Iterator[dict[str, Any]]
def _unit_test_skips(self) -> set[str]
Import
from river.base import Estimator
I/O Contract
Properties
| Property | Type | Description |
|---|---|---|
| _supervised | bool | Returns True if the estimator requires target values (y) during learning |
| _tags | set[str] | Returns tags specifying the estimator's input capabilities (text, categorical, etc.) |
Pipeline Composition
| Operator | Type | Description |
|---|---|---|
| Pipeline → Pipeline | Combines this estimator with another into a Pipeline |
Unit Testing Methods
| Method | Returns | Description |
|---|---|---|
| _unit_test_params() | Iterator[dict[str, Any]] | Yields parameter dictionaries for instantiating the estimator during tests |
| _unit_test_skips() | set[str] | Returns names of unit tests to skip for this estimator |
Usage Examples
from river import linear_model
from river import preprocessing
from river import compose
# Create estimators
scaler = preprocessing.StandardScaler()
model = linear_model.LinearRegression()
# Use | operator to create a pipeline
pipeline = scaler | model
# Check if supervised
print(model._supervised) # True
# Check tags
print(model._tags) # Set of capability tags
# For custom estimator implementations
class MyEstimator(Estimator):
@classmethod
def _unit_test_params(cls):
# Provide test parameters
yield {'param1': 1, 'param2': 'test'}
def _unit_test_skips(self):
# Skip specific tests if needed
return {'check_pickling'}
def _more_tags(self):
# Specify capabilities
return {'can_handle_text'}