This documentation is for scikit-learn version 0.11-gitOther versions

Citing

If you use the software, please consider citing scikit-learn.

This page

8.19.2. sklearn.multiclass.OneVsRestClassifier

class sklearn.multiclass.OneVsRestClassifier(estimator)

One-vs-the-rest (OvR) multiclass/multilabel strategy

Also known as one-vs-all, this strategy consists in fitting one classifier per class. For each classifier, the class is fitted against all the other classes. In addition to its computational efficiency (only n_classes classifiers are needed), one advantage of this approach is its interpretability. Since each class is represented by one and one classifier only, it is possible to gain knowledge about the class by inspecting its corresponding classifier. This is the most commonly used strategy for multiclass classification and is a fair default choice.

This strategy can also be used for multilabel learning, where a classifier is used to predict multiple labels for instance, by fitting on a sequence of sequences of labels (e.g., a list of tuples) rather than a single target vector. For multilabel learning, the number of classes must be at least three, since otherwise OvR reduces to binary classification.

Parameters :

estimator : estimator object

An estimator object implementing fit and one of decision_function or predict_proba.

Attributes

estimators_ list of n_classes estimators Estimators used for predictions.
label_binarizer_ LabelBinarizer object Object used to transform multiclass labels to binary labels and vice-versa.
multilabel_ boolean Whether a OneVsRestClassifier is a multilabel classifier.

Methods

fit(X, y) Fit underlying estimators.
get_params([deep]) Get parameters for the estimator
predict(X) Predict multi-class targets using underlying estimators.
score(X, y)
set_params(**params) Set the parameters of the estimator.
__init__(estimator)
fit(X, y)

Fit underlying estimators.

Parameters :

X : {array-like, sparse matrix}, shape = [n_samples, n_features]

Data.

y : array-like, shape = [n_samples]

or sequence of sequences, len = n_samples

Multi-class targets. A sequence of sequences turns on multilabel classification.

Returns :

self :

get_params(deep=True)

Get parameters for the estimator

Parameters :

deep: boolean, optional :

If True, will return the parameters for this estimator and contained subobjects that are estimators.

multilabel_

Whether this is a multilabel classifier

predict(X)

Predict multi-class targets using underlying estimators.

Parameters :

X: {array-like, sparse matrix}, shape = [n_samples, n_features] :

Data.

Returns :

y : array-like, shape = [n_samples]

Predicted multi-class targets.

set_params(**params)

Set the parameters of the estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns :self :