package sklearn

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type tag = [
  1. | `OneVsRestClassifier
]
type t = [ `BaseEstimator | `ClassifierMixin | `MetaEstimatorMixin | `MultiOutputMixin | `Object | `OneVsRestClassifier ] Obj.t
val of_pyobject : Py.Object.t -> t
val to_pyobject : [> tag ] Obj.t -> Py.Object.t
val as_classifier : t -> [ `ClassifierMixin ] Obj.t
val as_meta_estimator : t -> [ `MetaEstimatorMixin ] Obj.t
val as_multi_output : t -> [ `MultiOutputMixin ] Obj.t
val as_estimator : t -> [ `BaseEstimator ] Obj.t
val create : ?n_jobs:int -> estimator:[> `BaseEstimator ] Np.Obj.t -> unit -> t

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 2-d matrix in which cell i, j is 1 if sample i has label j and 0 otherwise.

In the multilabel learning literature, OvR is also known as the binary relevance method.

Read more in the :ref:`User Guide <ovr_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.

.. versionchanged:: v0.20 `n_jobs` default changed from 1 to None

Attributes ---------- estimators_ : list of `n_classes` estimators Estimators used for predictions.

classes_ : array, shape = `n_classes` Class labels.

n_classes_ : int Number of classes.

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.

Examples -------- >>> import numpy as np >>> from sklearn.multiclass import OneVsRestClassifier >>> from sklearn.svm import SVC >>> X = np.array( ... [10, 10], ... [8, 10], ... [-5, 5.5], ... [-5.4, 5.5], ... [-20, -20], ... [-15, -20] ... ) >>> y = np.array(0, 0, 1, 1, 2, 2) >>> clf = OneVsRestClassifier(SVC()).fit(X, y) >>> clf.predict([-19, -20], [9, 9], [-5, 5]) array(2, 0, 1)

val decision_function : x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

Returns the distance of each sample from the decision boundary for each class. This can only be used with estimators which implement the decision_function method.

Parameters ---------- X : array-like of shape (n_samples, n_features)

Returns ------- T : array-like of shape (n_samples, n_classes)

.. versionchanged:: 0.19 output shape changed to ``(n_samples,)`` to conform to scikit-learn conventions for binary classification.

val fit : x:[> `Spmatrix ] Np.Obj.t -> y:[> `Spmatrix ] Np.Obj.t -> [> tag ] Obj.t -> t

Fit underlying estimators.

Parameters ---------- X : (sparse) array-like of shape (n_samples, n_features) Data.

y : (sparse) array-like of shape (n_samples,) or (n_samples, n_classes) Multi-class targets. An indicator matrix turns on multilabel classification.

Returns ------- self

val get_params : ?deep:bool -> [> tag ] Obj.t -> Dict.t

Get parameters for this estimator.

Parameters ---------- deep : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns ------- params : mapping of string to any Parameter names mapped to their values.

val partial_fit : ?classes:[> `ArrayLike ] Np.Obj.t -> x:[> `Spmatrix ] Np.Obj.t -> y:[> `Spmatrix ] Np.Obj.t -> [> tag ] Obj.t -> t

Partially fit underlying estimators

Should be used when memory is inefficient to train all data. Chunks of data can be passed in several iteration.

Parameters ---------- X : (sparse) array-like of shape (n_samples, n_features) Data.

y : (sparse) array-like of shape (n_samples,) or (n_samples, n_classes) Multi-class targets. An indicator matrix turns on multilabel classification.

classes : array, shape (n_classes, ) Classes across all calls to partial_fit. Can be obtained via `np.unique(y_all)`, where y_all is the target vector of the entire dataset. This argument is only required in the first call of partial_fit and can be omitted in the subsequent calls.

Returns ------- self

val predict : x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

Predict multi-class targets using underlying estimators.

Parameters ---------- X : (sparse) array-like of shape (n_samples, n_features) Data.

Returns ------- y : (sparse) array-like of shape (n_samples,) or (n_samples, n_classes) Predicted multi-class targets.

val predict_proba : x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

Probability estimates.

The returned estimates for all classes are ordered by label of classes.

Note that in the multilabel case, each sample can have any number of labels. This returns the marginal probability that the given sample has the label in question. For example, it is entirely consistent that two labels both have a 90% probability of applying to a given sample.

In the single label multiclass case, the rows of the returned matrix sum to 1.

Parameters ---------- X : array-like of shape (n_samples, n_features)

Returns ------- T : (sparse) array-like of shape (n_samples, n_classes) Returns the probability of the sample for each class in the model, where classes are ordered as they are in `self.classes_`.

val score : ?sample_weight:[> `ArrayLike ] Np.Obj.t -> x:[> `ArrayLike ] Np.Obj.t -> y:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> float

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters ---------- X : array-like of shape (n_samples, n_features) Test samples.

y : array-like of shape (n_samples,) or (n_samples, n_outputs) True labels for X.

sample_weight : array-like of shape (n_samples,), default=None Sample weights.

Returns ------- score : float Mean accuracy of self.predict(X) wrt. y.

val set_params : ?params:(string * Py.Object.t) list -> [> tag ] Obj.t -> t

Set the parameters of this estimator.

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

Parameters ---------- **params : dict Estimator parameters.

Returns ------- self : object Estimator instance.

val estimators_ : t -> Py.Object.t

Attribute estimators_: get value or raise Not_found if None.

val estimators_opt : t -> Py.Object.t option

Attribute estimators_: get value as an option.

val classes_ : t -> [> `ArrayLike ] Np.Obj.t

Attribute classes_: get value or raise Not_found if None.

val classes_opt : t -> [> `ArrayLike ] Np.Obj.t option

Attribute classes_: get value as an option.

val n_classes_ : t -> int

Attribute n_classes_: get value or raise Not_found if None.

val n_classes_opt : t -> int option

Attribute n_classes_: get value as an option.

val label_binarizer_ : t -> Py.Object.t

Attribute label_binarizer_: get value or raise Not_found if None.

val label_binarizer_opt : t -> Py.Object.t option

Attribute label_binarizer_: get value as an option.

val multilabel_ : t -> bool

Attribute multilabel_: get value or raise Not_found if None.

val multilabel_opt : t -> bool option

Attribute multilabel_: get value as an option.

val to_string : t -> string

Print the object to a human-readable representation.

val show : t -> string

Print the object to a human-readable representation.

val pp : Format.formatter -> t -> unit

Pretty-print the object to a formatter.

OCaml

Innovation. Community. Security.