Data¶
churn_prediction.data.ingestion
¶
Kaggle Dataset Acquisition Module.
Provides utilities for downloading and managing customer churn datasets from Kaggle. It handles API authentication, idempotent downloads, and cleanup of unnecessary artifacts to ensure a clean raw data directory.
get_dataset(output_dir, expected_files=None, competition_name='playground-series-s6e3', *, force_download=False)
¶
Download and prepare the Kaggle competition dataset.
The function operates idempotently: when all expected dataset artifacts already exist locally and pass integrity checks, no download is performed. Otherwise, the dataset is downloaded, converted into the required format, and cleaned of unnecessary files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
Path or str
|
Destination directory for the dataset artifacts. |
required |
expected_files
|
frozenset of str or None
|
Set of filenames required for a valid local dataset. If |
None
|
competition_name
|
str
|
Kaggle competition identifier used to retrieve the dataset. |
"playground-series-s6e3"
|
force_download
|
bool
|
Whether to force dataset retrieval and processing even when the existing local files pass validation. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If required Kaggle credentials are unavailable. |
RuntimeError
|
If downloading, extracting, converting, or preparing the dataset fails. |
OSError
|
If required directories or dataset files cannot be created or modified. |
Source code in src/churn_prediction/data/ingestion.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
churn_prediction.data.schemas
¶
Dataset Validation Schemas.
This module defines Pandera schemas for validating the structure, data types, and value constraints of customer churn datasets. It ensures data quality by enforcing strict rules on nullability, uniqueness, and allowed categories across both raw and processed data stages.
churn_prediction.data.validation
¶
Dataset Validation Module.
Implements the validation logic for churn prediction datasets using Pandera schemas. It provides a workflow to load tabular data, verify its integrity against structural constraints, and persist detailed diagnostic reports in JSON format.
validate_dataset(dataset_path, report_path, schema, *, lazy=True)
¶
Validate a tabular dataset against a Pandera schema.
Loads the dataset according to its file format, validates its structure and values against the supplied Pandera schema, and writes a diagnostic JSON report describing the validation result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_path
|
str or Path
|
Path to the dataset being validated. Supported formats depend on the dataset loading implementation. |
required |
report_path
|
str or Path
|
Destination path for the generated JSON validation report. |
required |
schema
|
DataFrameSchema
|
Pandera schema defining the expected columns, data types, nullability, uniqueness constraints, and value restrictions. |
required |
lazy
|
bool
|
Whether Pandera should collect all validation failures before raising
an exception. When |
True
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If the dataset cannot be loaded or violates the supplied schema. |
OSError
|
If the validation report cannot be written to disk. |
Source code in src/churn_prediction/data/validation.py
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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |