Leave one out encoding of categorical features
Project description
leave-one-out-encoder
Leave one out coding for categorical features
See the source for this project here: https://github.com/welfare520/leave-one-out-encoder.
Getting Started
Installing
$ pip install loo_encoder
Example
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
loo_encoder-0.0.8.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for loo_encoder-0.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfdbad426764a683bdb5c409d127cfacefcbada06494cdceb434818ef9326feb |
|
MD5 | fa9fbcdff6d92ec5a4c3a2e19ce7a418 |
|
BLAKE2b-256 | e1e31a54a23f5121b1e28c837f2a19cbeccf190eddb927ae8cce803161ee4bda |