package sklearn

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type tag = [
  1. | `OutputCodeClassifier
]
type t = [ `BaseEstimator | `ClassifierMixin | `MetaEstimatorMixin | `Object | `OutputCodeClassifier ] 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_estimator : t -> [ `BaseEstimator ] Obj.t
val create : ?code_size:float -> ?random_state:int -> ?n_jobs:int -> estimator:[> `BaseEstimator ] Np.Obj.t -> unit -> t

(Error-Correcting) Output-Code multiclass strategy

Output-code based strategies consist in representing each class with a binary code (an array of 0s and 1s). At fitting time, one binary classifier per bit in the code book is fitted. At prediction time, the classifiers are used to project new points in the class space and the class closest to the points is chosen. The main advantage of these strategies is that the number of classifiers used can be controlled by the user, either for compressing the model (0 < code_size < 1) or for making the model more robust to errors (code_size > 1). See the documentation for more details.

Read more in the :ref:`User Guide <ecoc>`.

Parameters ---------- estimator : estimator object An estimator object implementing :term:`fit` and one of :term:`decision_function` or :term:`predict_proba`.

code_size : float Percentage of the number of classes to be used to create the code book. A number between 0 and 1 will require fewer classifiers than one-vs-the-rest. A number greater than 1 will require more classifiers than one-vs-the-rest.

random_state : int, RandomState instance or None, optional, default: None The generator used to initialize the codebook. Pass an int for reproducible output across multiple function calls. See :term:`Glossary <random_state>`.

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 `int(n_classes * code_size)` estimators Estimators used for predictions.

classes_ : numpy array of shape n_classes Array containing labels.

code_book_ : numpy array of shape n_classes, code_size Binary array containing the code of each class.

Examples -------- >>> from sklearn.multiclass import OutputCodeClassifier >>> from sklearn.ensemble import RandomForestClassifier >>> from sklearn.datasets import make_classification >>> X, y = make_classification(n_samples=100, n_features=4, ... n_informative=2, n_redundant=0, ... random_state=0, shuffle=False) >>> clf = OutputCodeClassifier( ... estimator=RandomForestClassifier(random_state=0), ... random_state=0).fit(X, y) >>> clf.predict([0, 0, 0, 0]) array(1)

References ----------

.. 1 'Solving multiclass learning problems via error-correcting output codes', Dietterich T., Bakiri G., Journal of Artificial Intelligence Research 2, 1995.

.. 2 'The error coding method and PICTs', James G., Hastie T., Journal of Computational and Graphical statistics 7, 1998.

.. 3 'The Elements of Statistical Learning', Hastie T., Tibshirani R., Friedman J., page 606 (second-edition) 2008.

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

Fit underlying estimators.

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

y : numpy array of shape n_samples Multi-class targets.

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 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 : numpy array of shape n_samples Predicted multi-class targets.

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 code_book_ : t -> [> `ArrayLike ] Np.Obj.t

Attribute code_book_: get value or raise Not_found if None.

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

Attribute code_book_: 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.