A probability-weighted target encoder.
Project description
Probability Target Encoder
A Python library for encoding categorical features using a probability-weighted target encoding technique.
This encoder extends the traditional target encoder by incorporating the probability that a target value exceeds the global target mean, and then uses the variance to increase confidence, producing encodings that capture both the average target value and the likelihood of above-average outcomes which has a higher confidence when the data isn't varied.
Features
- Handles categorical variables with numerical targets.
- Supports missing values.
- Encodes unseen categories using a fallback.
- Simple API with fit(), transform() and fit_transform() methods.
- Lightweight implementation with minimal dependencies.
Installation
pip install prob-target-encoder
Quick Start
from prob_target_encoder import ProbabilityTargetEncoder
encoder = ProbabilityTargetEncoder()
encoder.fit(train_column, train_target)
encoded_train = encoder.transform(train_column)
encoded_test = encoder.transform(test_column)
Example
import pandas as pd
from prob_target_encoder import ProbabilityTargetEncoder
X = pd.Series(["A", "B", "A", "C", "B"])
y = pd.Series([10, 20, 15, 8, 25])
encoder = ProbabilityTargetEncoder()
encoder.fit(X, y)
encoded = encoder.transform(X)
print(encoded)
How It Works
For each category, the encoder computes:
The mean target value for that category. The probability that the target exceeds the global target mean. the variance of the target value for each category. An encoding derived from these statistics.
Requirements
Python 3.9+ pandas
License
This project is licensed under the MIT License.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prob_target_encoder-0.1.0.tar.gz.
File metadata
- Download URL: prob_target_encoder-0.1.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a04ff1105eebe38c0b75d273968c9c9d918a04f61dc78a958ebd3251e97983b
|
|
| MD5 |
170f494dba4c4c2ea32badc1894a5abc
|
|
| BLAKE2b-256 |
0084261b6298f5afe453ecab061850cd95c832f1d515417f964f1b3cc8873d11
|
File details
Details for the file prob_target_encoder-0.1.0-py3-none-any.whl.
File metadata
- Download URL: prob_target_encoder-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d46aefac82abef3840c2f17772a8bf5ada6d511315040c1b7251b21255e5ab34
|
|
| MD5 |
b53c2cce4936f4c5bae1db68038bd535
|
|
| BLAKE2b-256 |
13658683a8773ddeb4ca8ea6476511ec47b0a6c9ab8818a9db78b8ba9c68ec5d
|