Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Label Encoding of the Target Variable | Processing Categorical Data
Data Preprocessing

Scorri per mostrare il menu

book
Label Encoding of the Target Variable

Let's go straight to the main thing - label encoding implements everything the same as ordinal encoder, but:

  • Methods work with different data dimensions;

  • The order of the categories is not important for label encoding.

How to use this method in Python:

1234567891011121314
from sklearn.preprocessing import LabelEncoder import pandas as pd # Simple categorical variable fruits = pd.Series(['apple', 'orange', 'banana', 'banana', 'apple', 'orange', 'banana']) # Create label encoder object le = LabelEncoder() # Fit and transform the categorical variable using label encoding fruits_encoded = le.fit_transform(fruits) # Print the encoded values print(fruits_encoded)
copy
Compito

Swipe to start coding

Read the dataset 'salary_and_gender.csv' and encode the output column 'Gender' with label encoding.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 3. Capitolo 4
single

single

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

close

Awesome!

Completion rate improved to 3.33

book
Label Encoding of the Target Variable

Let's go straight to the main thing - label encoding implements everything the same as ordinal encoder, but:

  • Methods work with different data dimensions;

  • The order of the categories is not important for label encoding.

How to use this method in Python:

1234567891011121314
from sklearn.preprocessing import LabelEncoder import pandas as pd # Simple categorical variable fruits = pd.Series(['apple', 'orange', 'banana', 'banana', 'apple', 'orange', 'banana']) # Create label encoder object le = LabelEncoder() # Fit and transform the categorical variable using label encoding fruits_encoded = le.fit_transform(fruits) # Print the encoded values print(fruits_encoded)
copy
Compito

Swipe to start coding

Read the dataset 'salary_and_gender.csv' and encode the output column 'Gender' with label encoding.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

close

Awesome!

Completion rate improved to 3.33

Scorri per mostrare il menu

some-alt