Automatic ML preprocessing pipeline
Project description
preprocessx 🔧
An automated machine learning preprocessing pipeline that handles the full data preparation workflow — from raw data to model-ready features — in just a few lines of code.
Table of Contents
Project Structure
vprojectx/
├── vprojectx/
│ ├── __init__.py
│ └── preprocessx.py
├── README.md
├── LICENSE
├── requirements.txt
└── pyproject.toml
| File / Folder | Purpose |
|---|---|
vprojectx/preprocessx.py |
Core pipeline class — all preprocessing logic lives here |
vprojectx/__init__.py |
Exposes preprocessx at the package level |
requirements.txt |
Runtime dependencies (pandas, numpy, scikit-learn) |
pyproject.toml |
Package metadata and build configuration |
LICENSE |
Project license |
Installation
Install the package directly from PyPI:
pip install vprojectx
install the dependencies manually:
pip install pandas numpy scikit-learn
Then import the class:
from vprojectx import preprocessx
Usage
pre = preprocessx(df, target='Churn')
pre.prepare(size=0.2)
pre.encode(remaining='auto')
pre.scale()
X_train = pre.X_train
X_test = pre.X_test
y_train = pre.y_train
y_test = pre.y_test
That's it. Three method calls and your data is clean, encoded, and scaled — ready to plug into any model.
API Reference
preprocessx(df, target)
Initializes the pipeline.
pre = preprocessx(df, target='Churn')
| Parameter | Type | Description |
|---|---|---|
df |
pd.DataFrame |
Your full dataset |
target |
str |
Name of the target column to predict |
Raises ValueError if the target column is not found in the DataFrame.
.prepare()
Cleans the data, splits into train/test, imputes missing values, and clips outliers.
pre.prepare(size=0.2, missing_threshold=0.5)
| Parameter | Type | Default | Description |
|---|---|---|---|
size |
float |
0.2 |
Fraction of data held out as the test set |
missing_threshold |
float |
0.5 |
Columns exceeding this fraction of missing values are dropped |
Returns X_train, X_test, y_train, y_test.
.encode()
Encodes categorical columns. You can specify how each column should be handled, or let the pipeline figure it out automatically.
pre.encode(hot=None, ordinal=None, remaining=None)
| Parameter | Type | Default | Description |
|---|---|---|---|
hot |
str or list |
None |
Column(s) to one-hot encode |
ordinal |
dict or list |
None |
Columns to ordinal encode. Pass a dict to set the category order, or a list to auto-assign codes |
remaining |
"auto" or None |
None |
Automatically encode any leftover categorical columns |
Returns X_train, X_test, y_train, y_test.
Examples:
# Let the pipeline handle everything
pre.encode(remaining='auto')
# One-hot encode specific columns
pre.encode(hot=['Gender', 'Region'])
# Ordinal encode with a defined order
pre.encode(ordinal={'Satisfaction': ['Low', 'Medium', 'High']})
# Mix all three
pre.encode(
hot=['Gender'],
ordinal={'Satisfaction': ['Low', 'Medium', 'High']},
remaining='auto'
)
When
remaining='auto', columns with more than 50 unique values are skipped. Binary columns are label-encoded (0/1). All others are one-hot encoded.
.scale()
Standardizes all numeric feature columns to zero mean and unit variance.
pre.scale()
X_train = pre.X_train
X_test = pre.X_test
y_train = pre.y_train
y_test = pre.y_test
Returns X_train, X_test, y_train, y_test. The target column is never scaled.
.help()
Prints a quick usage guide to the console.
pre.help()
How It Works — In Depth
prepare() (In Depth)
Calling .prepare() runs the following steps in order:
1. Remove Duplicates
Exact duplicate rows are dropped.
2. Drop Sparse Columns
Columns where the fraction of missing values exceeds missing_threshold are dropped. The dropped column names and their missing percentages are printed.
Dropping columns with >50.0% missing values:
- Cabin: 77.1% missing
3. Date Detection & Feature Engineering
Columns whose names contain "date", "time", or "timestamp" are automatically parsed as datetimes. Each detected column is then expanded into five numeric features:
| New Column | Description |
|---|---|
{col}_year |
Calendar year |
{col}_month |
Month (1–12) |
{col}_day |
Day of month |
{col}_dayofweek |
Day of week (0 = Monday) |
{col}_days_since |
Days elapsed since that date |
The original datetime column is dropped after extraction.
4. Train/Test Split
The data is split before any statistics are computed. This prevents data leakage — the pipeline never sees test data during fitting. random_state=42 is used for reproducibility.
5. Missing Value Imputation
Imputation strategies are learned from the training set only, then applied to both splits:
| Column Type | Condition | Strategy |
|---|---|---|
| Numeric | abs(skew) ≤ 1 | Mean |
| Numeric | abs(skew) > 1 | Median |
| Categorical | — | Mode |
6. Outlier Clipping
Outlier bounds are computed from training data and applied to both splits. The method chosen depends on skewness:
| Condition | Method | Bounds |
|---|---|---|
| abs(skew) < 1 | Z-score | Mean ± 3 standard deviations |
| abs(skew) ≥ 1 | IQR | Q1 − 1.5×IQR / Q3 + 1.5×IQR |
Values outside the bounds are clipped (not removed).
encode() (In Depth)
One-Hot Encoding (hot)
Uses sklearn.OneHotEncoder with drop='first' to avoid multicollinearity. Unknown categories in the test set are silently ignored.
Ordinal Encoding (ordinal)
- Dict: Maps categories to integers in the order you define — useful for columns with a meaningful hierarchy like
Low → Medium → High. - List: Uses pandas
cat.codesto assign integer codes automatically. Order is not guaranteed to be meaningful.
Auto Encoding (remaining='auto')
For any leftover categorical column not already handled:
- > 50 unique values → skipped (too high cardinality)
- 2 unique values → binary encoded (0 and 1)
- 3–50 unique values → one-hot encoded with
drop='first'
scale() (In Depth)
StandardScaler is fit on X_train numeric columns only, then applied to both train and test:
z = (x − mean) / std
mean and std come entirely from the training set, so test data is transformed with the same parameters — just as it would be in production.
Design Decisions
Why split before imputing? If you compute fill values on the full dataset, test-set values influence the training statistics. Splitting first ensures the pipeline mirrors real-world conditions.
Why median for skewed columns? The mean is pulled toward extreme values in skewed distributions. The median is a more robust estimate of center when the data has a long tail.
Why IQR for skewed outliers and Z-score for symmetric? Z-score assumes a roughly normal distribution. When data is skewed, the standard deviation is inflated by the tail, making Z-score unreliable. IQR is non-parametric and handles skewed data cleanly.
Why drop='first' in one-hot encoding?
Dropping one dummy per column avoids perfect multicollinearity, which can destabilize linear models.
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 vprojectx-0.1.1.tar.gz.
File metadata
- Download URL: vprojectx-0.1.1.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7b11d6625b92cb69dfec7075c505f7c3ec5d2a35d78beb6568560942e6a0c85
|
|
| MD5 |
7e4c188ec1a922f4f452e5ed1b0b3bb5
|
|
| BLAKE2b-256 |
aaf42624830fc024486f2c430aa7a7732eb711dfd5e40d40c5f41f4ea2def5bd
|
File details
Details for the file vprojectx-0.1.1-py3-none-any.whl.
File metadata
- Download URL: vprojectx-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
348abf8ca29b1a51b65b666e5d42b6c426bfbf49fcff2382ce35a0b43705af63
|
|
| MD5 |
37dbe11b83c552f5f90e239eb3cbfd1f
|
|
| BLAKE2b-256 |
3ac5ae852d411421b30dedeae3e7c815ee1eefc67b4a8c268df29bb3cc89a83a
|