Skip to content

MultiClassEncoder

Convert a multi-label task into multiclass.

Assigns a class to each unique combination of labels, and proceeds with training the supplied multi-class classifier.

The transformation is done by converting the label set, which could be seen as a binary number, into an integer representing a class. At prediction time, the predicted integer is converted back to a binary number which is the predicted label set.

Parameters

Examples

>>> from river import forest
>>> from river import metrics
>>> from river import multioutput
>>> from river.datasets import synth

>>> dataset = synth.Logical(seed=42, n_tiles=100)

>>> model = multioutput.MultiClassEncoder(
...     model=forest.ARFClassifier(seed=7)
... )

>>> metric = metrics.multioutput.MicroAverage(metrics.Jaccard())

>>> for x, y in dataset:
...    y_pred = model.predict_one(x)
...    metric = metric.update(y, y_pred)
...    model = model.learn_one(x, y)

>>> metric
MicroAverage(Jaccard): 95.41%

Methods

learn_one

Update the model with a set of features x and the labels y.

Parameters

  • x (dict)
  • y (Dict[Hashable, bool])

Returns

MultiLabelClassifier: self

predict_one

Predict the labels of a set of features x.

Parameters

  • x (dict)
  • kwargs

Returns

typing.Dict[typing.Hashable, bool]: The predicted labels.

predict_proba_one

Predict the probability of each label appearing given dictionary of features x.

Parameters

  • x (dict)
  • kwargs

Returns

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