package sklearn

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type tag = [
  1. | `LabelEncoder
]
type t = [ `BaseEstimator | `LabelEncoder | `Object | `TransformerMixin ] Obj.t
val of_pyobject : Py.Object.t -> t
val to_pyobject : [> tag ] Obj.t -> Py.Object.t
val as_transformer : t -> [ `TransformerMixin ] Obj.t
val as_estimator : t -> [ `BaseEstimator ] Obj.t
val create : unit -> t

Encode target labels with value between 0 and n_classes-1.

This transformer should be used to encode target values, *i.e.* `y`, and not the input `X`.

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

.. versionadded:: 0.12

Attributes ---------- classes_ : array of shape (n_class,) Holds the label for each class.

Examples -------- `LabelEncoder` can be used to normalize labels.

>>> from sklearn import preprocessing >>> le = preprocessing.LabelEncoder() >>> le.fit(1, 2, 2, 6) LabelEncoder() >>> le.classes_ array(1, 2, 6) >>> le.transform(1, 1, 2, 6) array(0, 0, 1, 2...) >>> le.inverse_transform(0, 0, 1, 2) array(1, 1, 2, 6)

It can also be used to transform non-numerical labels (as long as they are hashable and comparable) to numerical labels.

>>> le = preprocessing.LabelEncoder() >>> le.fit('paris', 'paris', 'tokyo', 'amsterdam') LabelEncoder() >>> list(le.classes_) 'amsterdam', 'paris', 'tokyo' >>> le.transform('tokyo', 'tokyo', 'paris') array(2, 2, 1...) >>> list(le.inverse_transform(2, 2, 1)) 'tokyo', 'tokyo', 'paris'

See also -------- sklearn.preprocessing.OrdinalEncoder : Encode categorical features using an ordinal encoding scheme.

sklearn.preprocessing.OneHotEncoder : Encode categorical features as a one-hot numeric array.

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

Fit label encoder

Parameters ---------- y : array-like of shape (n_samples,) Target values.

Returns ------- self : returns an instance of self.

val fit_transform : y:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

Fit label encoder and return encoded labels

Parameters ---------- y : array-like of shape n_samples Target values.

Returns ------- y : array-like of shape n_samples

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

Transform labels back to original encoding.

Parameters ---------- y : numpy array of shape n_samples Target values.

Returns ------- y : numpy array of shape n_samples

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

Transform labels to normalized encoding.

Parameters ---------- y : array-like of shape n_samples Target values.

Returns ------- y : array-like of shape n_samples

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 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 : Stdlib.Format.formatter -> t -> unit

Pretty-print the object to a formatter.