Skip to content
Work Practice Products Coding interviews Machine learning coding Quant developer HFT course Blog Method Why me About Enquire Book a call

Courses · Machine learning coding

Machine learning coding interview questions

The round where you are handed an empty editor and asked to write softmax, backpropagation or k-means without a library. 40 problems in 12 lessons, each with a live Python and NumPy editor, the tests it will be judged on, and a worked solution.

  • 12 lessons
  • 40 problems
  • 14 easy · 23 medium · 3 hard
  • Python and NumPy in the page
Not started

Start the course

Before the interview: the details that break when machine learning is written from scratch.

Course outline

12 lessons and 40 problems: 14 easy, 23 medium, 3 hard. Read the lesson, then solve its problems in order.

1Numerically stable softmax and log-sum-expEvery deep learning library hides this. Interviewers ask you to write it because most candidates have never had to.
2Linear and logistic regression from scratchThe model every other model is compared against, and the one interviewers use to find out whether you can differentiate a loss and vectorise the result.
3Backpropagation from scratchAutograd is a convenience. Interviewers for research roles want to see that you could do without it.
4Dropout, gradient clipping and learning-rate schedulesThe parts of a training loop that are not the model. Each is a few lines, and each has a convention an interviewer will check.
5Attention, normalisation and convolution from scratchThe four layers inside nearly every modern network. Each is a few lines of NumPy, and each has one convention that most candidates get wrong.
6LSTM and GRU cells, and beam search, from scratchTransformers replaced them in most products, not in interviews: a gated cell is the standard test of whether you can turn equations into code that matches a library exactly.
7Cosine search, contrastive loss and negative samplingRecommendation, search and retrieval-augmented generation all rest on three ideas: compare vectors by angle, train them by contrast, and make the training cheap with sampled negatives.
8k-means, kNN, PCA and decision trees from scratchOlder than deep learning and still asked, because each one fits in twenty lines and each one hides a decision about ties, signs or empty sets.
9Naive Bayes, EM, Viterbi and Markov chains from scratchFour models that predate deep learning and still turn up in research interviews, because each one tests whether you can keep probabilities from underflowing.
10Statistics coding questions: variance, AUC and rank correlationFormulas from a statistics course, rewritten for a computer: one pass, finite precision, ties handled.
11Statistical inference in code: standard errors, permutation tests, the Kalman filterAn estimate without its uncertainty is half an answer. Four pieces of inference, each small enough to write in an interview.
12NDCG, calibration error and macro-F1 from scratchA model is only as good as the number used to judge it. Each of these metrics hides a decision (a discount, a binning, an average) that changes the answer, and interviewers ask about exactly those decisions.

What this round tests

ML engineering and research interviews at large technology companies, AI labs and quant funds increasingly include a round that is neither LeetCode nor theory. You implement a piece of machine learning from first principles, in NumPy, and the interviewer watches how you handle shapes, numerical stability and the conventions that libraries normally hide.

The problems below are the ones that come up: a softmax that survives a logit of 1000, the gradient of a two-layer network by hand, attention with a causal mask, batch norm's two variances, k-means with an empty cluster, PCA with a sign convention, AUC with tied scores. Each is short. Each has one detail that most candidates miss, and the tests are written to find it.



How each problem works

  • A real editor. Python 3 with NumPy runs in your browser. Nothing to install, and your code never leaves your machine.
  • The real tests. Every problem is judged on a fixed table of cases, compared within a stated floating-point tolerance, including the overflow and tie cases that catch people.
  • Checked solutions. Every reference solution is verified before publication against an independent slow implementation: exact rational or 60-digit arithmetic, brute force, or finite differences for gradients, on the published tests and on 40 random inputs.
  • Timed attempts. Start the clock to work at interview pace, with a target time for each problem.
  • Ask AI about any line of a statement or a solution.

Related practice


Common questions

Which companies ask machine learning coding questions?

Machine learning engineer and research scientist loops at large technology companies and AI labs often include one implementation round, and quant funds ask research candidates for the statistics and linear algebra versions: PCA, regression, rank correlation. The format varies; the content is remarkably consistent, which is why a short list of problems covers most of it.

Can I use PyTorch or scikit-learn in the interview?

Usually not for the core of the problem. You are typically allowed NumPy, and asked to write the model, the loss or the layer yourself. The interviewer wants to see that you know what the library does, so these problems are set up the same way.

How much maths do I need?

Matrix calculus at the level of differentiating a loss with respect to a weight matrix, basic probability, and the idea of an eigenvector. Each lesson derives what its problems use, so the lessons double as revision.

Why are answers compared with a tolerance?

Two correct implementations of the same formula can differ in the last few digits because they add numbers in a different order. Every problem states its tolerance, typically a relative error of one in a billion, which is tight enough to catch a wrong formula and loose enough to accept any correct one.

Book the strategy hour — £250 What the hour covers →

Paid in full, in advance. No refunds. Full terms