Linear Models interview question

Machine LearningLinear ModelsRegression Metricsbasic

What does the mean squared error cost J(w) = (1/n) Σ (yᵢ − ŷᵢ)² measure for a linear regression model?

  1. AThe average absolute difference between predicted and actual targets, so every error counts linearly.
  2. BThe share of the target's variance that the model explains, reported on a scale from 0 to 1.
  3. CThe average squared difference between the predicted and the actual target values over the examples.
  4. DThe average squared distance between each feature and its own mean, measuring the spread of the inputs.
Show the answer and explanation

Correct answer: C, The average squared difference between the predicted and the actual target values over the examples.

Explanation Linear Models

The mean squared error (MSE) cost averages the squared residuals (yᵢ − ŷᵢ)² over the n training examples. Fitting a linear regression by least squares means choosing the weights w that make this cost as small as possible. For linear regression it is a convex quadratic function of w, so it has no spurious local minima.

Worked example: residuals 1, −1, 2, −2 give MSE = (1 + 1 + 4 + 4) / 4 = 2.5.

Why the other descriptions are wrong:

  • The average absolute difference is the mean absolute error (MAE), a different cost.
  • The share of explained variance is R², which is derived from the squared errors but is not the cost itself.
  • The spread of each feature around its mean is the feature variance; it involves no predictions at all.

Interview tip: mention that some courses write the cost as 1/(2n) Σ (yᵢ − ŷᵢ)²; the extra ½ only simplifies the gradient and does not change the minimizer.

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More Machine Learning questions

  1. What does the Gini impurity of a decision-tree node measure?
  2. Which statement correctly contrasts bagging and boosting?
  3. What is the "naive" assumption in Naive Bayes?
  4. Which description matches the standard k-means (Lloyd's) algorithm?
  5. What does precision measure for a binary classifier?