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.
10 write-ups
| Title |
|---|
| 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. |