Automated feature engineering: target-encodes strings, text-mines high-cardinality columns, and imputes missing values with cross-variable predictions.
Project description
model-preprocessor
Automated feature engineering for tabular data. Converts a raw DataFrame with mixed string/numeric columns and missing values into a fully numeric, fully imputed dataset ready for modeling.
What it does
-
Target-encodes low-cardinality strings (≤250 unique values by default): smoothed mean of the dependent variable per category, shrunk toward the overall mean for small groups using weight
sqrt(n)/sqrt(100). -
Text-mines high-cardinality strings (>250 unique values): tokenises values and one-hot encodes tokens that appear in at least max(30, 0.1%) of rows.
-
Imputes missing values by predicting each variable from all other variables using a fast model (Ridge regression by default).
Installation
pip install model-preprocessor
Quick start
import pandas as pd
from model_preprocessor import ModelPreprocessor
df = pd.read_csv("data.csv")
pp = ModelPreprocessor(target="revenue")
clean = pp.fit_transform(df)
# clean is fully numeric with no missing values
Parameters
| Parameter | Default | Description |
|---|---|---|
target |
(required) | Name of the dependent variable column |
max_unique |
250 |
Threshold for target-encoding vs text-mining |
min_token_count |
None |
Min rows a token must appear in (default: max(30, 0.1% of rows)) |
impute_model |
None |
sklearn estimator for imputation (default: Ridge(alpha=1.0)) |
API
pp = ModelPreprocessor(target="y")
pp.fit(train_df) # learn encodings and imputation models
result = pp.transform(df) # apply to new data
# or
result = pp.fit_transform(train_df) # fit + transform in one step
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 model_preprocessor-0.2.0.tar.gz.
File metadata
- Download URL: model_preprocessor-0.2.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6262f122c91417ae2df523a23f22d22c5a0bedc39b303c9a8e67206522ee690f
|
|
| MD5 |
fe58df13002bc377fbd569f34aa1bb9a
|
|
| BLAKE2b-256 |
388f332931ce98c0e47068123f983db9ac018f1a53bd2a710cb5bedf08f7f5a9
|
File details
Details for the file model_preprocessor-0.2.0-py3-none-any.whl.
File metadata
- Download URL: model_preprocessor-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbdbe402f02e445cda8b2507e769115b40aa14a5232a9563ad019ad02355c7b1
|
|
| MD5 |
406c056a0cb6e1d475ae6164da737142
|
|
| BLAKE2b-256 |
29e86ff87f8a62fbe7e53ddd28cfc67b0778c9b188f407cc5aa30cf434b72ab4
|