Machine Learning Medium technical 1 views 1 min read

Explain how gradient descent optimizes a model.

Peer-reviewed by HireXTech Technical Panel • Updated for 2025/2026 hiring • Editorial standards
Practise this track
Interviewer Expectations for this Question
01
Core Competency

Assesses fundamental understanding of Machine Learning conventions, runtime behavior, and memory/performance considerations.

02
Evaluation Criteria

Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.

Comprehensive Model Answer Verified Solution

Gradient descent minimizes a loss function by repeatedly moving parameters in the direction that decreases the loss. The gradient is the vector of partial derivatives, and you step opposite to it.

for epoch in range(epochs):
    preds = X @ w + b
    error = preds - y
    grad_w = (2/n) * X.T @ error
    grad_b = (2/n) * error.sum()
    w -= lr * grad_w
    b -= lr * grad_b

The learning rate is critical: too large and the loss diverges or oscillates, too small and training is slow. Variants: batch gradient descent uses all data per step (stable, slow), stochastic uses one example (noisy, fast), and mini-batch uses a small batch and is the standard. Momentum and Adam adapt the step per parameter. Always scale features, monitor the loss curve, and consider schedules or early stopping.

Candidate Response Strategy & Interview Tips

  1. Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
  2. Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
  3. Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
  4. Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.
Spotted an error or have an alternative solution?