๐Ÿ Capstone: NumPy Implementations vs Library Baselines

By Better Wise

You already have the harness from the previous lesson: fixed folds, fixed seeds, a timing wrapper, and a results schema. In this lesson you run every model through it, from the normal-equation linear regressor to the one-hidden-layer MLP, and publish one table that a skeptical reviewer can rerun. Nothing new gets implemented here. The work is integration, fairness, and reporting.

Important: The deliverable is a report, not a scoreboard. If your NumPy model loses on runtime and wins on nothing, that is still a successful capstone, provided the number is correctly measured and honestly explained.

The brief: one table, six rows, no asterisks

Your from-scratch code has been written in isolation, each model validated against its own unit test. The capstone asks the question those unit tests cannot answer: when every model is fed the same folds, the same preprocessing, and the same tuning budget, does the NumPy version behave like the scikit-learn counterpart on accuracy and loss, and how much wall-clock time does that cost?

Two outcomes are both legitimate. Parity in accuracy with a 10x runtime penalty is the expected result, and it is worth stating plainly: the value of the from-scratch version is transparency, not throughput. A mismatch is the more interesting outcome, because it means either your implementation or your protocol is wrong. Both are worth finding before you write the report.

Run this exercise first. Before writing any integration code, list for each of your six models the single parameter that most affects its runtime, for example the number of k-means iterations, the EM convergence tolerance, or the MLP epoch count. Write the pair (yours, baseline equivalent) next to each.

The specification

Build run_capstone.py that produces results.csv with one row per (model, dataset, fold) and these columns: model, impl (numpy or sklearn), dataset, fold, seed, accuracy, loss, fit_seconds, predict_seconds.

In this lesson

  • Order of work
  • Acceptance criteria
  • Pitfalls that produce impressive, wrong tables
  • Closing the loop

About this course

Part of Mathematics for Machine Learning 4: Build Core ML Algorithms from Scratch โ€” Turn three courses of math into working code: derive and implement regression, PCA, clustering, EM and backpropagation from scratch, finishing with a project that benchmarks your models.

Level
Advanced
Goal
Build a project
Language
English
Focus
from-scratch implementations gradient derivations PCA and SVD EM and clustering backpropagation
Prior knowledge
Linear algebra: matrices, eigenvalues, SVD, Calculus: gradients and chain rule, Probability: distributions and maximum likelihood, Python and NumPy
Practice
Exercises + capstone project
Time
~5.7h
Voice
a pragmatic ML engineer who refuses to let you write a line of NumPy until the gradient is derived on paper
Not covered
PyTorch and TensorFlow, Large-scale distributed training, Hyperparameter tuning platforms

This lesson is premium content. Sign in and purchase the course to view the full content. Sign in