Polynomial Regression — ML Technical Interview Questions & Answers

Fitting curved relationships with polynomial terms.

Polynomial Regression

  • Simple meaning: The truth may be a curve (practice helps a lot at first, then less). Polynomial regression adds hours², hours³, … then still fits a linear model on those new columns.
  • Picture: Degree 1 = straight line. Degree 2 = one bend. Degree 10 = a roller coaster through every point on train — overfit.
  • sklearn: PolynomialFeatures(degree=2) then LinearRegression, ideally in a Pipeline so test rows get the same powers.
  • Trap: a high degree because train R² looks perfect. Trap: forgetting to pipeline — test transform must match train.

Technical Interview Tip: Curve = extra columns like hours². Keep the degree small.

Code Examples for Polynomial Regression

Polynomial Regression — working example

# y ≈ 2x + 1
xs = [1, 2, 3, 4]
ys = [3, 5, 7, 9]
pred = [2 * x + 1 for x in xs]
mse = sum((y - p) ** 2 for y, p in zip(ys, pred)) / len(ys)
mae = sum(abs(y - p) for y, p in zip(ys, pred)) / len(ys)
print(pred, mse, mae)

Polynomial Regression — regression predicts continuous values; MSE squares errors, MAE uses absolute errors.

How to Explain Polynomial Regression to an Interviewer

Is polynomial still ‘linear’?

Linear in the weights Nonlinear in hours

Main risk?

High degree overfit