ML coding
Machine learning algorithms and model parts written from scratch in NumPy and PyTorch, as ML coding rounds ask.
Machine learning algorithms and model parts written from scratch in NumPy and PyTorch, as ML coding rounds ask.
23 write-ups
| Title |
|---|
| ML Coding Interviews: What to Expect What the ML coding round is, who gets it, NumPy versus PyTorch, what interviewers grade, a 45-minute plan, and how to prepare. |
| NumPy Essentials The NumPy you need to write ML code from scratch under time pressure: dtypes and views, broadcasting, turning loops into axes, axis arguments, einsum and fancy indexing. |
| Numerical Stability Why exp overflows and log underflows, and the fixes interviewers look for: log-sum-exp, stable softmax and sigmoid, losses from logits, sized epsilons, and float16 and bfloat16 pitfalls. |
| Getting Shapes Right Habits that keep shapes right in ML code: name every dimension, assert at boundaries, spot broadcasts that hide bugs, reshape versus transpose, and test on tiny inputs with sizes that all differ. |
| Debugging ML Code The find-the-bugs variant of the ML coding round: how to work it, and the bugs it plants: silent broadcasts, wrong axes, off-by-one masks, leaking state, and a loss that won't fall. |
| Linear Regression Linear regression in NumPy three ways: gradient descent with loops, vectorized gradient descent, and a closed form with ridge, then lasso by coordinate descent, with tests and the scaling questions. |
| Logistic Regression Logistic regression in NumPy, from loops to a stable vectorized fit with the loss computed from logits, then softmax for many classes, with tests and the versus-neural-network question. |
| K-Nearest Neighbors K-nearest neighbors in NumPy: a distance matrix without loops, top-k with argpartition, deterministic ties, classification and regression, chunking for memory, and choosing k. |
| K-Means Lloyd's k-means in NumPy, from a loop version to a vectorized one, with first-k and k-means++ initialization, empty clusters, a stopping rule and tests. |
| Decision Trees and Random Forests A CART classification tree in NumPy, from a brute-force split search to a sorted prefix-count one, then bagging, random forests and extra trees, with tests. |
| Naive Bayes Gaussian and multinomial naive Bayes in NumPy, from multiplied densities that underflow to vectorized log probabilities, with variance and Laplace smoothing and tests. |
| PCA PCA in NumPy, from a covariance matrix and eigendecomposition to a centered SVD, with sign conventions, explained variance, power iteration and tests. |
| Gaussian Mixtures and EM A Gaussian mixture fit with EM in NumPy, from densities that underflow to log-space responsibilities with Cholesky, covariance regularization, a stopping rule and tests. |
| Evaluation Metrics Precision, recall and F1, ROC AUC from a pairwise loop to an exact sort-based curve with ties, average precision, NDCG and a stable log loss, all in NumPy with tests. |
| Sampling Weighted sampling with and without replacement, an O(log k) draw with a Fenwick tree, weighted keys, reservoir sampling and a checkpointable weighted data batcher, with tests. |
| An MLP with Backprop by Hand A one-hidden-layer ReLU network with softmax cross-entropy in NumPy, backprop by hand from a per-example loop to modular layers, checked against finite differences and PyTorch. |
| Softmax and Cross-Entropy A stable softmax and cross-entropy in NumPy, from the formula that overflows to log-sum-exp, the combined gradient with respect to the logits, label smoothing and one gradient step. |
| Optimizers: SGD, Momentum, Adam SGD, momentum, Adam and AdamW in NumPy, with bias correction, L2 against decoupled weight decay, warmup and cosine schedules, checked against torch.optim. |
| BatchNorm and LayerNorm BatchNorm in NumPy with train and eval modes, running statistics and a hand-derived backward pass, then LayerNorm and RMSNorm, all checked against PyTorch. |
| Dropout and Regularization Inverted dropout as a NumPy layer with train and eval modes and a backward pass, then L2 regularization and early stopping on a model that overfits, with tests and PyTorch checks. |