mars.learn.preprocessing.LabelEncoder#
- class mars.learn.preprocessing.LabelEncoder[源代码]#
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 User Guide.
- classes_#
Holds the label for each class.
- Type
ndarray of shape (n_classes,)
参见
OrdinalEncoder
Encode categorical features using an ordinal encoding scheme.
OneHotEncoder
Encode categorical features as a one-hot numeric array.
实际案例
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']
- __init__()#
Methods
__init__
()fit
(y[, session, run_kwargs, execute])Fit label encoder.
fit_transform
(y[, session, run_kwargs])Fit label encoder and return encoded labels.
get_params
([deep])Get parameters for this estimator.
inverse_transform
(y[, session, run_kwargs])Transform labels back to original encoding.
set_params
(**params)Set the parameters of this estimator.
transform
(y[, session, run_kwargs, execute])Transform labels to normalized encoding.