One-vs-the-rest (OvR) multiclass strategy.
This strategy consists in fitting one binary classifier per class. Because we are in a streaming context, the number of classes isn't known from the start. Hence, new classifiers are instantiated on the fly. Likewise, the predicted probabilities will only include the classes seen up to a given point in time.
Note that this classifier supports mini-batches as well as single instances.
The computational complexity for both learning and predicting grows linearly with the number of classes. If you have a very large number of classes, then you might want to consider using an
A binary classifier, although a multi-class classifier will work too.
A mapping between classes and classifiers.
>>> from river import datasets >>> from river import evaluate >>> from river import linear_model >>> from river import metrics >>> from river import multiclass >>> from river import preprocessing >>> dataset = datasets.ImageSegments() >>> scaler = preprocessing.StandardScaler() >>> ovr = multiclass.OneVsRestClassifier(linear_model.LogisticRegression()) >>> model = scaler | ovr >>> metric = metrics.MacroF1() >>> evaluate.progressive_val_score(dataset, model, metric) MacroF1: 77.46%
This estimator also also supports mini-batching.
>>> for X in pd.read_csv(dataset.path, chunksize=64): ... y = X.pop('category') ... y_pred = model.predict_many(X) ... model = model.learn_many(X, y)
Return a fresh estimator with the same parameters.
The clone has the same parameters but has not been updated with any data. This works by looking at the parameters from the class signature. Each parameter is either - recursively cloned if it's a River classes. - deep-copied via
copy.deepcopy if not. If the calling object is stochastic (i.e. it accepts a seed parameter) and has not been seeded, then the clone will not be idempotent. Indeed, this method's purpose if simply to return a new instance with the same input parameters.
Update the model with a set of features
x and a label
Predict the label of a set of features
- x (dict)
typing.Union[bool, str, int]: The predicted label.
Predict the probability of each label for a dictionary of features
A dictionary that associates a probability which each label.