I knew the math going in but froze a little when they asked me to actually write it out step by step with explanations.
Start by clearly defining the linear regression model and the MSE cost function, then present clean pseudocode for batch gradient descent with explicit initialization, forward pass, gradient computation, and parameter updates. Walk through each step, explaining the purpose and the mathematical intuition, and mention practical considerations like convergence and learning rate.
Pro tip: Emphasize that batch gradient descent computes the gradient using the entire training set, which is computationally expensive but stable; contrast it with stochastic gradient descent to show awareness of trade-offs, and mention that feature scaling can significantly speed up convergence.
State the linear regression hypothesis h_θ(x) = θ^T x and the mean-squared error cost J(θ) = (1/2m) Σ (h_θ(x_i) - y_i)^2. Explain that the goal is to find θ that minimizes J(θ).
Set initial θ (e.g., zeros or small random values), choose learning rate α, and set convergence criteria (e.g., max iterations or gradient norm threshold).
For each iteration, compute the predicted values for all training examples, calculate the gradient of J(θ) with respect to each θ_j, and update θ_j simultaneously. Include pseudocode for the loop.
Derive the gradient: ∂J/∂θ_j = (1/m) Σ (h_θ(x_i) - y_i) x_i_j. Explain that this is the average of the errors times the feature values, and that it points in the direction of steepest ascent, so we subtract it.
Mention how to check for convergence (e.g., cost change below threshold), the impact of learning rate, and the importance of feature scaling. Also note that batch gradient descent can be slow for large datasets.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.