One-vs-one multiclass strategy
This strategy consists in fitting one classifier per class pair. At prediction time, the class which received the most votes is selected. Since it requires to fit `n_classes * (n_classes - 1) / 2` classifiers, this method is usually slower than one-vs-the-rest, due to its O(n_classes^2) complexity. However, this method may be advantageous for algorithms such as kernel algorithms which don't scale well with `n_samples`. This is because each individual learning problem only involves a small subset of the data whereas, with one-vs-the-rest, the complete dataset is used `n_classes` times.
Read more in the :ref:`User Guide <ovo_classification>`.
Parameters ---------- estimator : estimator object An estimator object implementing :term:`fit` and one of :term:`decision_function` or :term:`predict_proba`.
n_jobs : int or None, optional (default=None) The number of jobs to use for the computation. ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. ``-1`` means using all processors. See :term:`Glossary <n_jobs>` for more details.
Attributes ---------- estimators_ : list of ``n_classes * (n_classes - 1) / 2`` estimators Estimators used for predictions.
classes_ : numpy array of shape n_classes
Array containing labels.
n_classes_ : int Number of classes
pairwise_indices_ : list, length = ``len(estimators_)``, or ``None`` Indices of samples used when training the estimators. ``None`` when ``estimator`` does not have ``_pairwise`` attribute.
Examples -------- >>> from sklearn.datasets import load_iris >>> from sklearn.model_selection import train_test_split >>> from sklearn.multiclass import OneVsOneClassifier >>> from sklearn.svm import LinearSVC >>> X, y = load_iris(return_X_y=True) >>> X_train, X_test, y_train, y_test = train_test_split( ... X, y, test_size=0.33, shuffle=True, random_state=0) >>> clf = OneVsOneClassifier( ... LinearSVC(random_state=0)).fit(X_train, y_train) >>> clf.predict(X_test:10
) array(2, 1, 0, 2, 0, 2, 0, 1, 1, 1
)