Fourth phase of Arc 4. The ML lingua franca.

This phase makes you fluent in the Python ML stack: numpy, pandas, scikit-learn, at the level where you stop thinking about syntax and start thinking about what to compute. Vectorization replaces for-loops. Pandas DataFrames replace dict-of-lists. scikit-learn’s API conventions (fit/transform/predict) become reflex. By phase end you’ve trained a small model end-to-end on a real dataset with proper train/test discipline.

This is also where local ML development lives. The deployment pieces (operator-managed Ray, KServe) come in Phases 37-38. Phase 34 is your dev loop.


Prerequisites

  • Arc 1 Python fluency (Phase 2); Arc 3 distributed-systems understanding (Phase 21)
  • A modest dataset to learn on: your own chronicle weekly logs work great for a classification or anomaly-detection task

Why this phase exists

Most engineers who say “I know ML” mean “I’ve used sklearn once.” This phase installs the operational fluency: not just calling model.fit() but reasoning about features, leakage, vectorization, memory, the bias-variance trade-off. The fluency that lets you read any ML codebase without flinching.


The pattern-first frame

Same eight steps.


1. PROBLEM

You have data. You want to predict something from it: a label, a number, a cluster. The workflow is: explore → preprocess → train → evaluate → iterate. The Python ML stack (numpy + pandas + sklearn) is the canonical toolset for this workflow at small-to-medium scale.


2. PRINCIPLES

2.1 Vectorization as the muscle

In ML, for-loops are slow. Vectorized operations (numpy arrays, pandas Series) run in C, 100-1000× faster. The mental shift is “think in arrays, not elements.”

→ Pattern: vectorization-as-pattern

Investigate:

2.2 Train / test / validation split

You can’t evaluate a model on the data you trained it on (it memorizes). Split: train (fit), validation (tune), test (final report). Never let the test set touch hyperparameter tuning.

→ Pattern: train-test-split

Investigate:

2.3 Cross-validation

K-fold cross-validation gives a more reliable performance estimate by averaging across multiple splits. Stratified, group, time-series CV handle structure in the data.

→ Pattern: cross-validation

Investigate:

2.4 Feature engineering and scaling

Many models assume features on similar scales. Standardization (z-score), normalization (min-max), and log transforms each have a use case.

Investigate:

2.5 Bias-variance trade-off

A model can underfit (high bias, too simple) or overfit (high variance, too complex). The sweet spot depends on data size, complexity, regularization.

Investigate:

2.6 The sklearn API as design pattern

fit(X, y), transform(X), predict(X), score(X, y). Consistent across every estimator. Pipelines chain transformers + estimators. This is the API that defined the modern ML ecosystem.

Investigate:


3. TRADE-OFFS

DecisionOptionsCost
DataFrame librarypandas; Polars; DuckDBpandas: ubiquitous, slow. Polars: fast, Rust-backed, less ubiquitous. DuckDB: SQL + DataFrame hybrid.
Array librarynumpy; cupy (GPU); jax (auto-diff)numpy: standard. cupy: GPU. jax: research / numerical research.
ML libraryscikit-learn; XGBoost; LightGBM (Phase 35 deepens)sklearn: general. XGBoost/LightGBM: tabular winner.

4. TOOLS (as of 2026-06)

Reading


5. MASTERY: One model end-to-end on real data

[ ] Pick a real dataset (your chronicle logs, public dataset, your day-job data with permission)
[ ] Exploratory data analysis: distributions, missing values, correlations
[ ] Vectorize all your processing: no for-loops
[ ] Split: train / validation / test
[ ] Build a Pipeline with preprocessing + estimator
[ ] Cross-validate; report mean + std
[ ] Tune hyperparameters (GridSearchCV or RandomizedSearchCV) on validation
[ ] Evaluate on held-out test set: once, at the end
[ ] Write a model card documenting: problem, data, model, performance, limitations
[ ] Profile your training loop: where is time spent?

6. COMPARE: Polars or DuckDB

Reimplement one of your pandas pipelines in Polars (Rust-backed, fast) or DuckDB (SQL over DataFrames). Reflect on speed + ergonomics.

400-word reflection.


7. OPERATE


8. CONTRIBUTE


What ships from this phase


Validation criteria

[ ] End-to-end model on real data with proper train/test discipline
[ ] Pipeline-based preprocessing (no leakage)
[ ] Cross-validation done properly
[ ] Model card written
[ ] All 10 operational depth checks
[ ] Polars/DuckDB compare reflection (400 words)
[ ] 1-2 runbooks
[ ] Pattern entries:
    - vectorization-as-pattern → OUTLINE
    - train-test-split → OUTLINE
    - cross-validation → OUTLINE
[ ] Exit Test passed

Exit Test

Time: 2 hours.

Part 1: Build (75 min)

Given a new dataset (provided), build a complete pipeline: preprocess + model + evaluate. Properly cross-validated. Model card written.

Part 2: Diagnose (30 min)

A leakage scenario: model performs great on validation, terrible on a separate test set. Identify the leakage source.

Part 3: Articulate (15 min)

~400 words: “When would you reach for pandas vs Polars vs DuckDB for a 10GB CSV processing task?”


Anti-patterns

Anti-patternWhy
for-loops over pandas rows100-1000× slower than vectorized
Touching the test set during hyperparameter tuningInflated performance estimate
Scaling before splittingTest-set statistics leak into preprocessing
Single train/test split for small dataHigh variance in estimate; use CV
fit_transform on test dataShould be transform only

Patterns touched this phase


→ Next: Phase 35: Classical ML Engineering