Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
LabelEncoder | Preprocessing Data with Scikit-learn
ML Introduction with scikit-learn

LabelEncoderLabelEncoder

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 the OrdinalEncoder.
So we can just pass the y variable to the .fit_transform() method.

Choose the correct statement.

Виберіть правильну відповідь

Все було зрозуміло?

Секція 2. Розділ 7
course content

Зміст курсу

ML Introduction with scikit-learn

LabelEncoderLabelEncoder

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 the OrdinalEncoder.
So we can just pass the y variable to the .fit_transform() method.

Choose the correct statement.

Виберіть правильну відповідь

Все було зрозуміло?

Секція 2. Розділ 7
some-alt