Features¶
churn_prediction.features.train_preprocessing
¶
Train Data Preprocessing Module.
Provides functionality to clean, encode, and split the raw churn dataset into training and validation sets. It ensures consistent feature scaling and type casting to prepare the data for model training.
preprocess_train_dataset(raw_input_path, train_output_path, val_output_path, preprocessor_path)
¶
Prepare the raw training dataset for model development.
Loads the raw dataset, applies deterministic binary feature mappings, performs a stratified train-validation split, fits the ordinal encoder exclusively on the training partition, and transforms both partitions using the fitted encoder.
The resulting processed datasets and fitted preprocessing artifact are persisted to disk for subsequent training and inference stages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_input_path
|
str or Path
|
Path to the raw input dataset. |
required |
train_output_path
|
str or Path
|
Destination path for the processed training dataset. |
required |
val_output_path
|
str or Path
|
Destination path for the processed validation dataset. |
required |
preprocessor_path
|
str or Path
|
Destination path for the serialized preprocessing artifact. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the raw input dataset does not exist. |
ValueError
|
If binary mapping, schema alignment, stratified splitting, encoding, or feature type conversion fails. |
RuntimeError
|
If a processed dataset or preprocessing artifact cannot be persisted. |
Source code in src/churn_prediction/features/train_preprocessing.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 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 183 184 185 186 187 188 189 | |
churn_prediction.features.inference_preprocessing
¶
Inference data preprocessing module for churn prediction.
This module provides functionality to transform raw input datasets into a format compatible with the trained churn prediction model, ensuring consistency in binary mapping, ordinal encoding, and data types.
preprocess_inference_dataset(raw_input_path, processed_output_path, fitted_encoder)
¶
Transform a raw inference dataset into model-ready features.
Applies the same binary mappings, categorical encoding, feature ordering, and data type conversions used during model training. The supplied pre-fitted encoder is reused without modification to ensure training and inference transformations remain consistent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_input_path
|
str or Path
|
Path to the raw dataset that will be scored. |
required |
processed_output_path
|
str or Path
|
Destination path for the processed inference dataset. |
required |
fitted_encoder
|
OrdinalEncoder
|
Encoder fitted during the training preprocessing stage. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the raw input dataset cannot be found. |
ValueError
|
If the input schema, binary mappings, categorical values, feature alignment, or data type conversions are invalid. |
RuntimeError
|
If the processed inference dataset cannot be persisted. |
Source code in src/churn_prediction/features/inference_preprocessing.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |