Preprocessing overview
The Preprocessor (pretab.preprocessor.Preprocessor) is the main entry point. It
inspects a pandas.DataFrame, decides which columns are numerical and which are
categorical, and builds a scikit-learn ColumnTransformer that applies a chosen strategy
per feature.
How feature types are detected
By default, columns are classified automatically:
Numerical: continuous columns, and integer columns with enough distinct values.
Categorical: string/object columns, and low-cardinality integer columns.
The behaviour is controlled by several constructor arguments:
cat_cutoffThreshold that decides whether an integer column is treated as categorical.
treat_all_integers_as_numericalWhen
True, every integer column is treated as numerical regardless of cardinality.
Choosing strategies
There are two ways to configure preprocessing:
Globally via
numerical_methodandcategorical_method.Per feature via the
feature_preprocessingdict, which overrides the global defaults for specific columns.
from pretab import Preprocessor
# Global strategy for every column of a given type
preprocessor = Preprocessor(
numerical_method="ple",
categorical_method="int",
)
# Or override individual columns
preprocessor = Preprocessor(
feature_preprocessing={
"age": "ple",
"income": "rbf",
"city": "one-hot",
},
)
Numerical strategies
Strategy |
Transformer |
Notes |
|---|---|---|
|
|
Zero mean, unit variance |
|
|
Scaled to |
|
|
Rank-based normalisation |
|
|
Robust to outliers |
|
|
Polynomial interactions |
|
|
Positive inputs only |
|
|
Handles zero/negative values |
|
|
Piecewise linear encoding |
|
|
Rule- or tree-based binning |
|
|
Radial basis functions |
|
|
ReLU basis expansion |
|
|
Sigmoid basis expansion |
|
|
Tanh basis expansion |
|
|
B-spline basis |
|
|
Natural cubic spline |
|
|
Penalised B-spline |
|
|
Tensor-product spline |
|
|
Thin-plate regression spline |
|
|
Pass-through |
Categorical strategies
Strategy |
Transformer |
Notes |
|---|---|---|
|
|
Integer/ordinal encoding (default) |
|
|
One-hot encoding |
|
|
One-hot from pre-encoded ordinals |
|
|
Pretrained language embeddings |
|
|
Binning of categorical codes |
|
|
Pass-through |
Note
The pretrained strategy requires the optional sentence-transformers dependency.
Install it with pip install "pretab[embeddings]".
Output format
fit_transform and transform return a dictionary that maps each feature to its
transformed array (keys are prefixed with num_ or cat_). Pass return_array=True
to transform to receive a single stacked numpy.ndarray instead.
X_dict = preprocessor.fit_transform(df, y) # {"num_age": ..., "cat_city": ...}
X_array = preprocessor.transform(df, return_array=True) # single ndarray
Use get_feature_info(verbose=True) to inspect the resolved strategy and output
dimensionality of every feature.
Using transformers directly
Every transformer listed above is also importable from pretab.transformers and works as
a standalone scikit-learn transformer, so it can be composed into any Pipeline or
ColumnTransformer. See the Quickstart for examples,
and the API Reference for the full parameter list of each class.