Maths for machine learning interview questions
12 questions interviewers ask on why maths matters, from first principles to the follow-ups. The first 3 model answers are free to read; Pro opens the rest.
- What does a linear model compute for one row?
A weighted sum: each feature times its weight, all added, which is the dot product of the feature vector and the weight vector. The first feature is a constant one, so its weight, the intercept, is added to every prediction. For Grace's shop on 1 January 2025 the five products add up to
3,051.11with the full weights. - How do you compute predictions for a whole table, and why not a loop?
As one matrix–vector product,
X @ w: every row ofXdotted with the samew. For the shop year that is2,920predictions in one line. A Python loop gives the same numbers, but NumPy runs the products and sums in compiled code over the whole array, which is much faster and is what every library does. - A feature has the largest weight in a linear model. Is it the most important feature?
Not from that alone. A weight is measured per unit of its feature. In the shop model, promotion's weight is
287.17dollars per promotion and footfall's is2.66dollars per visitor, but a day has 0 or 1 promotions and hundreds of visitors, so on Grace's day footfall's product is about9.09times promotion's. Compare contributions (weight times value), or compare weights only after putting the features on one scale. - Why is the mean squared error used, rather than the mean error?
- The mean squared error is 26,841.46. How far off is the model on a typical day?
- What does the derivative of the loss with respect to a weight tell you?
- What is the gradient, and how does gradient descent use it?
- How would you check that a hand-written gradient is correct?
- Why do probabilistic models work with sums of log-probabilities?
- What is underflow, and where does a float64 hit it?
- Two models both give the data a likelihood that prints 0.0. How do you compare them?
- Multiplying the day-by-day probabilities assumes something. What?