▶ Data-flow diagram — self-contained HTML, opens in a browser — no install, no build
Situation
Every later ML task — regression, classification, clustering — rests on preprocessing. If the test set leaks into training, or missing values are handled by hand, any model further up the stack is invalidated and the result no longer reproduces on another machine.
The Machine Learning A-Z course supplies the structure, but its code (sklearn.cross_validation, Imputer, OneHotEncoder(categorical_features=)) was removed from scikit-learn in 0.22 — it has to be migrated to the modern API.
Task
I needed the preprocessing built correctly for modern scikit-learn: no leakage into training, no reliance on a random seed, and reproducible at every stage of the pipeline.
Actions
Preprocessing
python/data_preprocessing.py builds one ColumnTransformer over Data.csv:
- Missing data — mean imputation via
SimpleImputer. - Categoricals —
OneHotEncoderfor features andLabelEncoderfor the target. - Split — deterministic: rows are stable-sorted by
(Country, Age)and every fifth row becomes the test set, with no random seed. - Scaling —
StandardScaleron numeric columns only.
The whole transformer is fit on the training split only, so no test information leaks into preprocessing.
Datasets and EDA
python/generate_dummy_data.py is a deterministic generator (seeded RNG) for extra datasets, one per pipeline stage:
| File | Rows | Pipeline stage |
|---|---|---|
Data_large.csv |
400 | extended preprocessing |
Salary_Data_large.csv |
300 | simple linear regression |
Housing_Data.csv / .sql |
500 | multiple regression |
Customer_Churn.csv / .json |
800 | classification |
python/eda_plots.py renders a chart for every dataset into output/ — one figure per dataset plus a combined dashboard.png, all in one dark_background style, OO matplotlib, 300 dpi.
Run
pip install -r requirements.txt
cd python
python3 data_preprocessing.py # prints Train: (8, 5), Test: (2, 5)
python3 generate_dummy_data.py # synthetic datasets
cd ..
python python/eda_plots.py # charts into output/
Result
The outcome is a correct, reproducible preprocessing pipeline rather than a model: the test set does not leak into training, and the split repeats on any machine.
- Preprocessing is one pipeline fit on the training split only: the test set does not leak into training.
- The split reproduces without a seed: on
Data.csv— Train(8, 5), Test(2, 5). - Six course datasets plus four synthetic ones (400, 300, 500 and 800 rows).
- EDA charts for each dataset in one
dark_backgroundstyle at 300 dpi, plus a combineddashboard.png. - Code migrated to the modern scikit-learn API.
- 21 tests (7 + 9 + 5) keep the pipeline runnable: data_preprocessing, eda_plots, generate_dummy_data.
What I learned
Preprocessing is where most of an ML result is quietly won or lost. A pipeline fit on the whole dataset slips the test into training and inflates everything above it; the correct version is boring, and that is the point — the boring version is what makes model comparisons mean anything.
The second lesson is reproducibility without a seed you hope to remember. A seed is a hidden parameter that is easy to lose; a split taken by sorting on stable keys turns “it worked on my machine” into a property of the code rather than the environment.
Discussion points
- Why one transformer fit only on train. Any transform that has seen the test set contaminates the evaluation, and the contamination is invisible in the score.
- Why a deterministic split rather than a seeded one. A seed is a hidden parameter; sorting on stable keys is a property that repeats on any machine.
- Why the project stops at preprocessing. The value is the foundation later models stand on, not the score of one of them.
- What I would do differently. Add an explicit leakage test that fails if the transformer is fit before the split, instead of relying on code review.
Limitations
This is a learning project: the datasets are course and synthetic data, not production. The goal is a correct and reproducible pipeline, not model quality on real data.