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 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


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.1.tar.gz (3.6 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.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: prob_target_encoder-0.1.1.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

Hashes for prob_target_encoder-0.1.1.tar.gz
Algorithm Hash digest
SHA256 01ef8c10a559d7b965813ce8d6f364f2775ecfc76debf1bd904c5572b3b778ae
MD5 1c348224f2095e4c75815fd4f4c6563f
BLAKE2b-256 01b1b521ffc98f5c8dcd357b552f0fe5dd45399ed343d961836d10c5211dd20b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prob_target_encoder-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e99a8ee910be862cdba0aa72432b024d0e456835f7d03251287870730471bf5
MD5 c822f154c4abf135684dec5872776483
BLAKE2b-256 c958700a869cc95cb1fbce87c2f90cfcbf1654935d1e8c914e8f3fadc3414312

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