Skip to content

Instantly share code, notes, and snippets.

@dleybz
Created May 18, 2023 19:14
Show Gist options
  • Select an option

  • Save dleybz/2b9620835d63e1b6e4a88ede6ce214d1 to your computer and use it in GitHub Desktop.

Select an option

Save dleybz/2b9620835d63e1b6e4a88ede6ce214d1 to your computer and use it in GitHub Desktop.
from category_encoders import TargetEncoder
def encode_categorical(df):
te = TargetEncoder()
cols = df.select_dtypes('object').columns
for col in cols:
df.loc[:, col] = te.fit_transform(X=df[col], y=df['FraudFound'])
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment