model_preprocessing¶
Stateless input normalization and train-fitted classification preprocessing.
CrossFittedTargetEncoder
¶
Bases: TransformerMixin, BaseEstimator
Fixed, classification-only sklearn target encoding for actual TRAIN rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
random_state
|
int
|
Five-fold shuffled stratification seed. Smoothing is fixed to |
42
|
Notes
Each actual categorical fit requires every class at least five times.
Missing values remain a category, distinct from literal marker-like strings;
other scalar values are type-prefixed without fitting a vocabulary.
fit_transform returns sklearn's cross-fitted matrix directly. transform
uses the full-TRAIN fitted mappings, so fit(X, y).transform(X) is NOT a
replacement for the training matrix. Encoded training matrices are not cached.
Active use requires sklearn >=1.4, imported lazily. No group/time metadata,
sample weights, external validation, or regression targets are supported.
Source code in featcopilot/utils/model_preprocessing.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
fit(X, y, **fit_params)
¶
Fit encodings; use fit_transform, not a later transform, to train a learner.
Source code in featcopilot/utils/model_preprocessing.py
fit_transform(X, y, **fit_params)
¶
Return cross-fitted TRAIN encodings and retain only fitted inference state.
Source code in featcopilot/utils/model_preprocessing.py
get_encoding_report()
¶
Return counts/policy/actual output size, never maps, priors, or row encodings.
get_feature_names_out(input_features=None)
¶
Return model-input names, not generated-feature definitions.
Source code in featcopilot/utils/model_preprocessing.py
transform(X)
¶
Apply only full-TRAIN fitted maps; unknown categories use their fitted prior.
Source code in featcopilot/utils/model_preprocessing.py
encode_class_weights(weights, classes)
¶
Copy original-label weights into the fitted contiguous class vocabulary.
Source code in featcopilot/utils/model_preprocessing.py
make_classification_pipeline(train, estimator, *, numeric_clip_quantiles=(0.0, 1.0), categorical_encoding='one_hot', random_state=42)
¶
Build matched numeric/OHE preprocessing around an owned classifier clone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train
|
DataFrame
|
Post-generation training schema. No statistics are read here. |
required |
estimator
|
sklearn estimator
|
Unfitted classifier owned by the caller, not an external fitted model. |
required |
numeric_clip_quantiles
|
tuple[float, float]
|
Numeric bounds fitted by the pipeline, after feature generation. |
(0.0, 1.0)
|
categorical_encoding
|
('one_hot', 'target')
|
Target encoding is fixed cross-fitted IID classification. Empty categorical blocks retain the numeric-only path, with no target-encoder import or fit. |
"one_hot"
|
random_state
|
int
|
Target-encoder fold seed; ignored by the unchanged one-hot path. |
42
|
Returns:
| Type | Description |
|---|---|
Pipeline
|
Numeric clipping, median imputation/scaling and categorical OHE, then the supplied classifier. This is not a native-categorical representation. |
Source code in featcopilot/utils/model_preprocessing.py
normalize_categorical_frame(X)
¶
Normalize scalar category types and missingness without learning statistics.
Source code in featcopilot/utils/model_preprocessing.py
normalize_model_frame(schema, X, *, preserve_categorical_types=False)
¶
Normalize rows using only raw schema, without fitting any statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
DataFrame
|
Empty, unmodified raw training schema. Column order and numeric/boolean roles are authoritative; categorical levels are not used for encoding. |
required |
X
|
DataFrame
|
Training or inference rows. Numeric infinities become missing; missing categories remain distinct from literal strings. Boolean dtype persists. |
required |
preserve_categorical_types
|
bool
|
Target-only policy: preserve raw categorical scalars and missing values for the shared typed encoder and feature generation. Retain a supplied categorical dtype, otherwise use object dtype so numeric-looking category values cannot become numeric features. Never cast to fitted category levels, which would erase unseen values. False preserves legacy OHE string normalization exactly. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Independent normalized rows, with no imputation or learned vocabulary. |
Source code in featcopilot/utils/model_preprocessing.py
validate_categorical_encoding(value)
¶
Require one of the two explicit model-input categorical policies.
Source code in featcopilot/utils/model_preprocessing.py
validate_classification_frame(X)
¶
Require nonempty DataFrames with unique string feature names.