Learn AI.
OPTIONAL IMPLEMENTATION STUDIO · CLASSICAL ML

Build a pipeline you can evaluate.

Treat preprocessing, model fitting and selection as one experiment. Inspect every boundary before trusting a score.

The browser preview requires no installation. The Python exercise uses local CPU computation and public Iris measurements. Running supplied code is guided execution; independent implementation needs your code, tests and review. This optional studio does not change existing path requirements or award mastery. Learner pilots and human review remain pending.

Start from the skill you need

Recommended preparation: P02 files and NumPy arrays, validation boundaries, and simple baselines. Skip familiar explanations and try the implementation checks directly. Refresh a mean, probability or logarithm where it appears; the no-code trace remains open to everyone.

The task is binary classification: predict virginica versus the other Iris species using four measurements in centimeters. A probability of 0.5 or more predicts virginica. This is a different task from predicting petal length in the linear-regression project; compare models only within a shared task.

Try → predict → experiment

Predict whether a repeated measurement in both fitting and validation makes the new-group question easier. Then open the shared synthetic trace: compare row folds, group folds and forward-time folds, and inspect the preprocessing means. This is a nearest-neighbor teaching example, not a browser execution of scikit-learn or the Iris classifier.

Open the no-install fold and leakage workbench

Record why the validation policy matches the question. A new group requires separation by group; future observations require training times before validation times. Neither rule guarantees representativeness. The Python Iris exercise uses measurement groups; Iris has no observation timestamps, so the separate time-contract exercise is synthetic.

Run a complete library pipeline

Download these files into the same folder:

Use Python 3.11 or newer. The isolated environment instructions in P02 also explain the Windows interpreter path. On macOS/Linux, run:

python3 -m venv .venv
.venv/bin/python -m pip install -r pipeline-requirements.txt
.venv/bin/python classical-pipeline.py --develop > development.json
.venv/bin/python -m pip freeze > environment-freeze.txt

On Windows use py -3 -m venv .venv, then replace .venv/bin/python with .venv\Scripts\python.exe. Installation needs network access; fitting afterward uses the downloaded files locally. The verified reference is Python 3.12.14, NumPy 2.3.5 and scikit-learn 1.7.2 on macOS ARM64. Record your environment; other platforms are not yet verified.

  1. Choose a training fold
  2. Fit missing-value means on that fold
  3. Fit column scaling on filled training values
  4. Fit the candidate
  5. Transform and predict validation rows without fitting again

The loader verifies the exact source hash/size and removes one duplicate feature vector. It uses 89 training, 30 development and 30 reserved evaluation groups. This three-way studio protocol differs from the original two-way feasibility manifest. IDs were generated for the CSV; group equality is based on measured features, not confirmed specimen identity.

Three group folds divide the 89 training groups. Each training row receives one out-of-fold prediction. Pool their mistakes and divide by 89: if 8 are wrong, error rate is 8 ÷ 89 ≈ 9.0%. This weights rows equally even when fold sizes differ. The report also shows each fold's IDs, fill values and scaling means. Inspect them before comparing scores.

Fixed candidate menu: four choices, sixteen fits per development command
CandidateWhat is learnedDeclared bounds
majorityMost frequent training classNo feature-based decision
logisticA weighted score, intercept and sigmoid probabilityC = 1; at most 500 solver iterations
tree-depth-2Feature thresholdsDepth 2; minimum leaf size 2
tree-depth-4Feature thresholdsDepth 4; minimum leaf size 2

For logistic regression, C is the inverse strength of the weight penalty: smaller C imposes a stronger penalty. This menu fixes C at 1 rather than tuning it. Tree depth limits the number of successive splits; minimum leaf size requires at least two training examples in a final region.

There are twelve fold fits and four fits on all 89 training rows for development diagnostics. Sixteen fits do not represent equal computational work across algorithms. The script suggests the fewest pooled validation errors; ties use the listed candidate order. If you choose using the separate development score, state that additional selection explicitly. Neither score is final evidence after selection.

Iris has no missing feature values in this local source, so the imputer is present to teach the contract. Add a controlled missing-value case to test it. An entirely missing training column is rejected. Scaling is useful for the logistic model and redundant for ordinary axis-aligned tree decisions; the uniform pipeline makes the fitting boundary inspectable.

Implement → inspect → repair

  1. Complete learner_probability. Calculate score s = Σ xⱼwⱼ + b: multiply each transformed feature xⱼ by its weight wⱼ, add the products, then add bias b. Return 1 ÷ (1 + exp(−s)). Here exp means the exponential function e raised to its input. At s = 0 this is 0.5; at s = 1 it is about 0.7311. Review the visual logistic-regression lesson for how the score becomes a probability. The docstring supplies a stable two-branch calculation for extreme scores.
  2. Run classical-pipeline.py --check with your environment's Python. The learner TODO intentionally fails until implemented. Add a case with a different number of features, a nonzero bias and unchanged input arrays.
  3. Compare your probabilities with the fitted logistic model on development rows, using its stored imputer, scaler, weights and bias. Do not fit another scaler on the prediction rows. Report discrepancies with a numerical tolerance.
  4. In a separate experimental copy, move scaling outside the fold loop. Compare the fitted means with the correct report. A similar accuracy does not make the information leak acceptable. Restore the correct boundary and add a test that changes validation inputs without changing fitted training statistics.
  5. Use the grouped and forward-time helpers on repeated synthetic groups/timestamps. Confirm disjoint groups and strictly later validation times. The visible checks are practice; ask a reviewer to supply a new group/time arrangement.

Complete the existing manual linear-regression starter for the continuous-target part of P03. P02 supplies the manual preprocessing exercise. Together these tasks cover manual calculations and library comparison; a library score alone does not demonstrate those implementations.

Read probability metrics carefully

Accuracy counts correct thresholded decisions. Positive recall is the fraction of actual virginica examples predicted virginica; it is undefined if no positive examples are present. Confusion-matrix rows are true labels and columns predicted labels, ordered other then virginica. Log loss penalizes probability assigned away from the true class. The library clips exact zero/one probabilities at numerical precision, so the reported log loss is a finite numerical convention, not the mathematical negative logarithm of zero. Compare it alongside counts and the task's error consequences.

Freeze the recipe before reserved evaluation

Select a candidate, document the evidence and leave the evaluation command unused until that choice is fixed. Replace the example reason with your actual reasoning:

.venv/bin/python classical-pipeline.py --freeze choice.json --candidate logistic --reason "Record the evidence and limitations here"
.venv/bin/python classical-pipeline.py --evaluate choice.json > evaluation.json

The new freeze file contains inert JSON: candidate, reason, source hash, code hashes, environment versions, fitted imputer/scaler/model values and training/development IDs. Existing files are not overwritten. Evaluation refits the frozen candidate on the same 89 training rows and requires exact replay; it does not add development rows or silently select a new model. A changed script, loader or environment requires investigation. Keep the original artifact and explain any new protocol; do not rename a new run into old evidence.

A sibling exposure receipt is written before results are printed. Repeated requests for that filename are labelled practice. Editable local files cannot enforce first exposure across renamed/copied/deleted files or devices. Iris is public and has appeared in earlier lessons; a first receipt is not proof of unseen data. Do not tune on the final outcomes and then claim an independent test.

The program never loads serialized Python model objects. Replay needs both local scripts and the pinned packages; the JSON alone is not a standalone deployable model.

Evidence and continuation

  • Understanding: explain one fitted fold mean, one classification error and why preprocessing belongs inside the fold.
  • Implementation: provide manual preprocessing/linear/logistic functions, tests, source/license record, environment freeze, all candidate results, selection reason, frozen recipe and evaluation output. A reviewer supplies an unfamiliar split/prediction case and independently replays the artifact.
  • Decision: compare missed positives and false alarms, justify the selected candidate, state what the public sample cannot establish, and define what new evidence is needed before use.

Reports and code stay in your local folder; this studio has no My Work draft or review-state storage. Public checks, guided execution, independent implementation and human review remain distinct. Human review and representative learner pilots remain pending.

Continue the real-data comparison project · Continue to P04 numerical networks · Return to Explore

Reference APIs: scikit-learn Pipeline, GroupKFold, and DecisionTreeClassifier. Data: Fisher (1936), Iris, UCI, CC BY 4.0.

Learn AI · Understand by doing.Loading local progress…Copyright (c) 2026 Mobi Weave, Inc. All rights reserved