Linear & Logistic Regression
Time Limit: 30 minutes
Total Marks: 40
Instructions: Answer all questions. Use notation for math where required. Show working for derivations and numeric problems.
Q1. State the simple linear regression model equation and briefly define each term. (3 marks)
Q2. Write the Mean Squared Error (MSE) cost function for linear regression over examples. State the gradient descent update rule for parameter with learning rate . (4 marks)
Q3. Given the data points , use the ordinary least squares formulas to find the slope and intercept of the best-fit line. (6 marks)
Q4. State the normal equation closed-form solution for the parameter vector in linear regression. Name one situation where it cannot be applied directly. (3 marks)
Q5. List four key assumptions of linear regression. (4 marks)
Q6. Define (coefficient of determination) in terms of and . Write the formula for adjusted and explain why it is preferred when adding predictors. (5 marks)
Q7. Write the sigmoid function . Compute and evaluate the class label predicted (using threshold 0.5) when . (4 marks)
Q8. Write the log-loss (binary cross-entropy) for a single training example with true label and predicted probability . Compute the loss when and (use ). (4 marks)
Q9. Contrast L1 (Lasso) and L2 (Ridge) regularization: give the penalty term added to the cost for each, and state one distinguishing effect of each on coefficients. (4 marks)
Q10. In logistic regression, a coefficient . Interpret its meaning in terms of the odds. (3 marks)
End of Paper
Answer keyMark scheme & solutions
Q1. (3 marks)
Model: — 1 mark.
- : dependent/response variable; : independent/predictor variable — 0.5
- : intercept, : slope — 1
- : random error term (mean 0) — 0.5
Q2. (4 marks)
Cost: — 2 marks (accept without the factor if consistent).
Update: — 2 marks.
Why: gradient descent moves parameters opposite the gradient of to minimise error.
Q3. (6 marks)
Means: , — 1 mark.
— 1.
Numerator: — 1.5.
Denominator: — 1.
— 0.5.
— 1.
Line: .
Q4. (3 marks)
Normal equation: — 2 marks.
Cannot be applied when is non-invertible (singular) — e.g. redundant/linearly dependent features or when features samples — 1 mark.
Q5. (4 marks — 1 each)
Any four of:
- Linearity (relationship between predictors and response is linear).
- Independence of errors.
- Homoscedasticity (constant error variance).
- Normality of residuals.
- No (perfect) multicollinearity among predictors.
Q6. (5 marks)
— 2 marks.
, where =samples, =predictors — 2 marks.
Preferred because it penalises adding predictors that don't improve the model; plain never decreases when adding variables — 1 mark.
Q7. (4 marks)
— 1.5 marks.
— 1.
→ predicted class — 1.5.
Q8. (4 marks)
— 2 marks.
With : — 2 marks.
Q9. (4 marks)
L1 (Lasso): penalty — 1. Effect: drives some coefficients exactly to 0 → feature selection/sparsity — 1.
L2 (Ridge): penalty — 1. Effect: shrinks coefficients toward 0 smoothly but rarely exactly to 0 — 1.
Q10. (3 marks)
In logistic regression the log-odds are linear in features. A coefficient means a one-unit increase in multiplies the odds by — 2 marks, i.e. the odds roughly double, holding other features constant — 1 mark.
[
{"claim":"OLS slope for (1,2),(2,2),(3,4) is 1","code":"xs=[1,2,3]; ys=[2,2,4]; xb=sum(xs)/3; yb=Rational(8,3); num=sum((x-xb)*(y-yb) for x,y in zip(xs,ys)); den=sum((x-xb)**2 for x in xs); b1=num/den; result = (b1==1)"},
{"claim":"OLS intercept is 2/3","code":"xs=[1,2,3]; ys=[2,2,4]; xb=Integer(2); yb=Rational(8,3); b1=Integer(1); b0=yb-b1*xb; result = (b0==Rational(2,3))"},
{"claim":"sigmoid(-2) is below 0.5 (predict class 0)","code":"z=-2; s=1/(1+exp(-z)); result = bool(s<Rational(1,2))"},
{"claim":"log-loss for y=1,yhat=0.8 approx 0.2231","code":"L=-ln(Rational(8,10)); result = bool(abs(L-0.2231435513)<1e-6)"},
{"claim":"exp(0.7) approx 2.0138 (odds roughly double)","code":"result = bool(abs(exp(Rational(7,10))-2.013752707)<1e-6)"}
]