LabelEncoder
The OrdinalEncoder
and OneHotEncoder
are usually used to encode features (the X
variable).
But the target (y
variable) can also be categorical.
Let's look at the example:
The LabelEncoder
is used to encode the target, regardless of whether it is nominal or ordinal.
ML models do not consider the order of the target, allowing it to be encoded as any numerical values.
LabelEncoder
encodes the target to numbers 0, 1, ...
The code above encodes the target using LabelEncoder
and then uses the .inverse_transform()
method to convert it back to the original representation.
Note
Since the
LabelEncoder
is used to transform target (y
), which is usually a single column, it works well with pandas Series, unlike theOrdinalEncoder
.
So we can just pass they
variable to the.fit_transform()
method.
Tudo estava claro?
Conteúdo do Curso
ML Introduction with scikit-learn
1. Machine Learning Concepts
2. Preprocessing Data with Scikit-learn
ML Introduction with scikit-learn
LabelEncoder
The OrdinalEncoder
and OneHotEncoder
are usually used to encode features (the X
variable).
But the target (y
variable) can also be categorical.
Let's look at the example:
The LabelEncoder
is used to encode the target, regardless of whether it is nominal or ordinal.
ML models do not consider the order of the target, allowing it to be encoded as any numerical values.
LabelEncoder
encodes the target to numbers 0, 1, ...
The code above encodes the target using LabelEncoder
and then uses the .inverse_transform()
method to convert it back to the original representation.
Note
Since the
LabelEncoder
is used to transform target (y
), which is usually a single column, it works well with pandas Series, unlike theOrdinalEncoder
.
So we can just pass they
variable to the.fit_transform()
method.
Tudo estava claro?