Skip to main content

Leave one out encoding of categorical features

Project description


Leave one out coding for categorical features

See the source for this project here:

Getting Started


$ pip install loo_encoder


Fit encoder according to X and y, and then transform it.

from loo_encoder.encoder import LeaveOneOutEncoder
import pandas as pd
import numpy as np

enc = LeaveOneOutEncoder(cols=['gender', 'country'], handle_unknown='impute', sigma=0.02, random_state=42)

X = pd.DataFrame(
        "gender": ["male", "male", "female", "male"],
        "country": ["Germany", "USA", "USA", "UK"],
        "clicks": [10, 33, 47, 21]

y = pd.Series([150, 250, 300, 100], name="orders")

df_train = enc.fit_transform(X=X, y=y, sample_weight=X['clicks'])

Perform the transformation to new categorical data.

X_val = pd.DataFrame(
        "gender": ["unknown", "male", "female", "male"],
        "country": ["Germany", "USA", "Germany", "Japan"]

df_test = enc.transform(X=X_val)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
loo_encoder-0.0.9-py3-none-any.whl (4.3 kB) Copy SHA256 hash SHA256 Wheel py3 Aug 4, 2018
loo_encoder-0.0.9.tar.gz (3.7 kB) Copy SHA256 hash SHA256 Source None Aug 4, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page