Machine learning coding practice

Practice the ML code that interviews and real systems actually use.

A focused lab for metrics, losses, feature pipelines, retrieval, ranking, and debugging utilities.

def precision_at_k(labels, scores, k):
    order = sorted(range(len(scores)), key=scores.__getitem__, reverse=True)
    top_k = order[:k]
    return sum(labels[i] for i in top_k) / max(k, 1)
3 / 3 tests passed

Tracks

Built around practical ML engineering tasks.

Metrics

precision@k, recall@k, NDCG, MAP, AUC, log loss, calibration, and grouped metrics.

Loss & Training

Binary cross entropy, softmax CE, pairwise ranking loss, focal loss, sampling, and IPS weighting.

Data & Features

Mini-batches, normalization, categorical encoding, padding, time windows, dedupe, and time splits.

Retrieval & Ranking

Top-k heaps, cosine similarity, nearest neighbors, inverted indexes, BM25, and reranker interfaces.

Debugging Utilities

Dataset comparison, null and drift checks, feature distributions, segment labels, calibration buckets, and confusion matrices.

Starter Problems

First exercises to ship.

  1. 01 Implement precision_at_k with stable tie handling.
  2. 02 Compute NDCG for a batch of ranked queries.
  3. 03 Write binary cross entropy with sample weights.
  4. 04 Build a time-based train/test split without leakage.
  5. 05 Return top-k nearest items using cosine similarity.
  6. 06 Compare feature distributions across two datasets.

Roadmap

Next: turn this homepage into an interactive coding lab.

The first production milestone is a Python editor, public and hidden tests, user progress, and a curated set of 30 interview-grade ML coding exercises.