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)
   y_pred = {k: y_pred.get(k, 0) for k in y}
   metric.update(y, y_pred)
   model.learn_one(x, y)

metric
MicroAverage(Jaccard): 95.10%

Methods

learn_one

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

Parameters

  • x'dict'
  • y'dict[FeatureName, bool]'

predict_one

Predict the labels of a set of features x.

Parameters

  • x'dict'
  • kwargs

Returns

dict[FeatureName, bool]: The predicted labels.

predict_proba_one

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

Parameters

  • x'dict'
  • kwargs

Returns

dict[FeatureName, dict[bool, float]]: A dictionary that associates a probability which each label.