package sklearn

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type tag = [
  1. | `OrdinalEncoder
]
type t = [ `BaseEstimator | `Object | `OrdinalEncoder | `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 : ?categories:[ `A_list_of_array_like of Py.Object.t | `Auto ] -> ?dtype:Py.Object.t -> unit -> t

Encode categorical features as an integer array.

The input to this transformer should be an array-like of integers or strings, denoting the values taken on by categorical (discrete) features. The features are converted to ordinal integers. This results in a single column of integers (0 to n_categories - 1) per feature.

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

.. versionchanged:: 0.20.1

Parameters ---------- categories : 'auto' or a list of array-like, default='auto' Categories (unique values) per feature:

  • 'auto' : Determine categories automatically from the training data.
  • list : ``categoriesi`` holds the categories expected in the ith column. The passed categories should not mix strings and numeric values, and should be sorted in case of numeric values.

The used categories can be found in the ``categories_`` attribute.

dtype : number type, default np.float64 Desired dtype of output.

Attributes ---------- categories_ : list of arrays The categories of each feature determined during fitting (in order of the features in X and corresponding with the output of ``transform``).

See Also -------- sklearn.preprocessing.OneHotEncoder : Performs a one-hot encoding of categorical features. sklearn.preprocessing.LabelEncoder : Encodes target labels with values between 0 and n_classes-1.

Examples -------- Given a dataset with two features, we let the encoder find the unique values per feature and transform the data to an ordinal encoding.

>>> from sklearn.preprocessing import OrdinalEncoder >>> enc = OrdinalEncoder() >>> X = ['Male', 1], ['Female', 3], ['Female', 2] >>> enc.fit(X) OrdinalEncoder() >>> enc.categories_ array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object) >>> enc.transform(['Female', 3], ['Male', 1]) array([0., 2.], [1., 0.])

>>> enc.inverse_transform([1, 0], [0, 1]) array(['Male', 1], ['Female', 2], dtype=object)

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

Fit the OrdinalEncoder to X.

Parameters ---------- X : array-like, shape n_samples, n_features The data to determine the categories of each feature.

y : None Ignored. This parameter exists only for compatibility with :class:`sklearn.pipeline.Pipeline`.

Returns ------- self

val fit_transform : ?y:[> `ArrayLike ] Np.Obj.t -> ?fit_params:(string * Py.Object.t) list -> x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters ---------- X : numpy array of shape n_samples, n_features Training set.

y : numpy array of shape n_samples Target values.

**fit_params : dict Additional fit parameters.

Returns ------- X_new : numpy array of shape n_samples, n_features_new Transformed array.

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

Convert the data back to the original representation.

Parameters ---------- X : array-like or sparse matrix, shape n_samples, n_encoded_features The transformed data.

Returns ------- X_tr : array-like, shape n_samples, n_features Inverse transformed array.

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

Transform X to ordinal codes.

Parameters ---------- X : array-like, shape n_samples, n_features The data to encode.

Returns ------- X_out : sparse matrix or a 2-d array Transformed input.

val categories_ : t -> Np.Numpy.Ndarray.List.t

Attribute categories_: get value or raise Not_found if None.

val categories_opt : t -> Np.Numpy.Ndarray.List.t option

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