mojolearn.LabelEncoder#

class mojolearn.LabelEncoder[source]#

Bases: _PrepBase

Encode target labels as integers 0 to n_classes - 1.

Follows scikit-learn’s LabelEncoder. classes_ are the sorted distinct labels and transform returns each label’s index as int32. Numeric and string labels are supported. A label not seen in fit raises ValueError in transform and inverse_transform.

Variables:
  • classes_ (array or list) – Sorted distinct labels: an int64 array for integer labels, a float64 array for real labels, otherwise a list.

  • numeric_mode_ (str) – Numeric mode at fit time; transform runs in the same mode.

Examples

>>> import numpy as np, mojolearn
>>> enc = mojolearn.LabelEncoder().fit(np.array([10, 30, 20, 10]))
>>> enc.transform(np.array([30, 10]))
>>> enc.inverse_transform(np.array([0, 2]))
__init__()#

Methods

fit(y)

fit_transform(y)

Fit to X, then transform X.

get_params([deep])

Return the constructor parameters as a dict.

inverse_transform(y)

set_params(**params)

Set constructor parameters.

transform(y)

fit_transform(y)[source]#

Fit to X, then transform X.

Returns:

array – The transformed data.