13 · Project: ANN binary classifier (numpy end-to-end)
Build a complete 2-layer ANN classifier from scratch in numpy — forward pass, BCE loss, manual backprop, mini-batch SGD — then compare with the PyTorch equivalent.
Build a complete ANN binary classifier from scratch in numpy — end-to-end, no PyTorch needed — then look at the PyTorch read-along version side by side.
Without this:
All the lessons stay theoretical; this project shows the assembly.
This is the synthesis of chapters 1-3. You know the moving parts: forward pass, BCE loss, backpropagation (chain rule), gradient descent, He init, dropout. Now you assemble them into a working binary classifier — no frameworks, just numpy.
The payoff is double:
- You'll see exactly which lines of PyTorch correspond to which lines of the manual version.
- You'll have a mental debugging model: when something goes wrong in a PyTorch net, you'll know what the framework is doing underneath.
The dataset is synthetic (4 features, 500 samples, 2 classes) generated by scikit-learn's make_classification. We'll compare our hand-rolled ANN against a logistic regression baseline and show that the hidden layer enables non-linear decision boundaries.
Python (in browser)
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Python (in browser)
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Python (in browser)
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Python (in browser)
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Python (in browser)
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
PyTorch read-along: the exact same 2-layer ANN in ~30 lines
Your hand-rolled ANN beats logistic regression on this dataset because...
- A 2-layer ANN forward pass: X -> (W1*X+b1) -> ReLU -> (W2*a1+b2) -> sigmoid -> probability.
- Backprop through sigmoid+BCE simplifies to dz2 = (p - y)/m — one of the clean coincidences of calculus.
- Mini-batch SGD with momentum: cache velocity v = b*v - lr*grad; param += v.
- The ANN outperforms logistic regression because the hidden layer enables non-linear decision boundaries in feature space.
Every PyTorch tutorial on tabular classification ships an almost identical script. Knowing it from scratch lets you debug 'why isn't my loss decreasing' in any framework.
If you remove it: You'd use PyTorch's abstractions as a black box — and have no mental model for what's happening when training fails.