utils.wrappers.river#

This module contains River Model Wrappers to turn the output of river models into lists or arrays.

Classes

RiverMetricToLossFunction(river_metric[, ...])

Wrapper that transforms a river.metrics.base.Metric into a loss function.

RiverWrapper(prediction_function)

Wrapper for river prediction functions.

class utils.wrappers.river.RiverMetricToLossFunction(river_metric, dict_input_metric=False)[source]#

Bases: object

Wrapper that transforms a river.metrics.base.Metric into a loss function.

This Wrapper turns metrics that expect a single value as predictions (e.g. river.metrics.MAE, or river.metrics.Accuracy) or metrics that expect a dictionary as predictions (e.g. river.metrics.CrossEntropy) into a similar interface.

__call__(y_true, y_prediction)[source]#

Calculates the loss given for a single prediction given its true (expected) value.

Parameters:
  • y_true (Any) – The true labels.

  • y_prediction (dict) – The predicted values.

Returns:

The loss value given the true and predicted labels.

class utils.wrappers.river.RiverWrapper(prediction_function)[source]#

Bases: Wrapper

Wrapper for river prediction functions.

This wrapper turns any prediction function ouput into an iterable (list or np.ndarray) output.

Examples

Basic usage:

>>> from river.ensemble import AdaptiveRandomForestClassifier
>>> model = AdaptiveRandomForestClassifier()
>>> model_function = RiverWrapper(model.predict_one)

For classifiers returning probas:

>>> model_function = RiverWrapper(model.predict_proba_one)
__call__(x)[source]#

Runs the model and transforms the output into a list or np.ndarray.

Parameters:

x (Union[list, dict]) – Input instance as a dictionary of feature value pairs or a list of dictionaries.

Return type:

Union[dict, List[dict]]