Skip to main content

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 ProbTargetEncoder

encoder = ProbTargetEncoder()

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 ProbTargetEncoder

X = pd.Series(["A", "B", "A", "C", "B"])
y = pd.Series([10, 20, 15, 8, 25])

encoder = ProbTargetEncoder()
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


Download files

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

Source Distribution

prob_target_encoder-0.1.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prob_target_encoder-0.1.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file prob_target_encoder-0.1.2.tar.gz.

File metadata

  • Download URL: prob_target_encoder-0.1.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for prob_target_encoder-0.1.2.tar.gz
Algorithm Hash digest
SHA256 403ed9fb822408dbaf712195c4561dbf79e7c203624f6384a8f743e04996f332
MD5 de6f0899ed8def961f7ff07c0f14d98d
BLAKE2b-256 91b26f66852df54883860bd150e68545bce52862a9520659f8e9fd3652678ed7

See more details on using hashes here.

File details

Details for the file prob_target_encoder-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for prob_target_encoder-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 999c5881c3645aeb1c00a15a64981f6bc52cae6cd116351aa75df17ac8fa8188
MD5 4fa613c76d56fec7a8317a66b1cd181e
BLAKE2b-256 f227b2ab483dfe9d725bdf769128bcedaa4c65118c5f9e6e9b074d4328dcb514

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page