Caractéristiques catégorielles

Remporter une compétition Kaggle en Python

Yauhen Babakhin

Kaggle Grandmaster

Encodage par étiquette

ID Variable catégorielle
1 A
2 B
3 C
4 A
5 D
6 A
ID Encodage d'étiquettes
1 0
2 1
3 2
4 0
5 3
6 0
Remporter une compétition Kaggle en Python

Encodage par étiquette

# Import LabelEncoder
from sklearn.preprocessing import LabelEncoder

# Create a LabelEncoder object le = LabelEncoder()
# Encode a categorical feature df['cat_encoded'] = le.fit_transform(df['cat'])
     ID   cat  cat_encoded
0     1   A    0
1     2   B    1
2     3   C    2
3     4   A    0
Remporter une compétition Kaggle en Python

Encodage One-Hot

ID Variable catégorielle
1 A
2 B
3 C
4 A
5 D
6 A
ID Cat == A Cat == B Cat == C Cat == D
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 1 0 0 0
5 0 0 0 1
6 1 0 0 0
Remporter une compétition Kaggle en Python

Encodage One-Hot

# Create One-Hot encoded features
ohe = pd.get_dummies(df['cat'], prefix='ohe_cat')

# Drop the initial feature df.drop('cat', axis=1, inplace=True)
# Concatenate OHE features to the dataframe df = pd.concat([df, ohe], axis=1)
     ID ohe_cat_A ohe_cat_B ohe_cat_C ohe_cat_D
0     1         1         0         0         0
1     2         0         1         0         0
2     3         0         0         1         0
3     4         1         0         0         0
Remporter une compétition Kaggle en Python

Caractéristiques binaires

# DataFrame with a binary feature
binary_feature
      binary_feat
0     Yes
1     No
le = LabelEncoder()
binary_feature['binary_encoded'] = le.fit_transform(binary_feature['binary_feat'])
  binary_feat binary_encoded
0     Yes     1
1     No      0
Remporter une compétition Kaggle en Python

Autres méthodes d'encodage

  • Backward Difference Coding
  • BaseN
  • Binaire
  • CatBoost Encoder
  • Hachage
  • Encodage de Helmert
  • Encodeur de James-Stein
  • Leave One Out
  • Estimation M
  • One-Hot
  • Ordinal
  • Encodage polynomial
  • Encodage sommatif
  • Encodeur par cible
  • Poids de la preuve
Remporter une compétition Kaggle en Python

Autres méthodes d'encodage

  • Backward Difference Coding
  • BaseN
  • Binaire
  • CatBoost Encoder
  • Hachage
  • Encodage de Helmert
  • Encodeur de James-Stein
  • Leave One Out
  • Estimation M
  • One-Hot
  • Ordinal
  • Encodage polynomial
  • Encodage sommatif
  • Encodeur par cible
  • Poids de la preuve
Remporter une compétition Kaggle en Python

Passons à la pratique !

Remporter une compétition Kaggle en Python

Preparing Video For Download...