PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Machine Learning/Amazon

Implement SGD for linear regression and derive gradients

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of gradient-based optimization and linear model training, including competency in deriving gradients for mean squared error and implementing stochastic (or mini-batch) gradient descent for parameter estimation.

  • medium
  • Amazon
  • Machine Learning
  • Machine Learning Engineer

Implement SGD for linear regression and derive gradients

Company: Amazon

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Technical Screen

## Prompt You are given a dataset of \(n\) 1D samples \(\{(x_i, y_i)\}_{i=1}^n\), where \(x_i\) and \(y_i\) are real numbers. We want to fit a linear model: \[ \hat{y} = a x + b \] by minimizing the mean squared error (MSE). ## Tasks 1. **Define the loss** function for this problem (e.g., MSE over the dataset). 2. Using the chain rule / backprop-style reasoning, **derive the gradients** \(\frac{\partial L}{\partial a}\) and \(\frac{\partial L}{\partial b}\). 3. Describe (and optionally write pseudocode for) how to **train \(a\) and \(b\) using SGD** (or mini-batch SGD): - parameter initialization - per-step gradient computation - update rule - learning rate choice / scheduling - stopping criteria 4. Discuss common **pitfalls and edge cases** (e.g., scaling, divergence, choosing batch size). ## Output / Expected Result After training, return the learned parameters \(a\) and \(b\) that approximately minimize the chosen loss on the provided data.

Quick Answer: This question evaluates understanding of gradient-based optimization and linear model training, including competency in deriving gradients for mean squared error and implementing stochastic (or mini-batch) gradient descent for parameter estimation.

Related Interview Questions

  • Explain Core ML Interview Concepts - Amazon (hard)
  • Evaluate NLP Classification Models - Amazon (easy)
  • Explain overfitting, regularization, and LLM techniques - Amazon (medium)
  • Explain NLP/RL concepts used in LLM agents - Amazon (hard)
  • Design and evaluate a RAG system - Amazon (easy)
Amazon logo
Amazon
Dec 15, 2025, 12:00 AM
Machine Learning Engineer
Technical Screen
Machine Learning
5
0

Prompt

You are given a dataset of nnn 1D samples {(xi,yi)}i=1n\{(x_i, y_i)\}_{i=1}^n{(xi​,yi​)}i=1n​, where xix_ixi​ and yiy_iyi​ are real numbers.

We want to fit a linear model:

y^=ax+b\hat{y} = a x + by^​=ax+b

by minimizing the mean squared error (MSE).

Tasks

  1. Define the loss function for this problem (e.g., MSE over the dataset).
  2. Using the chain rule / backprop-style reasoning, derive the gradients ∂L∂a\frac{\partial L}{\partial a}∂a∂L​ and ∂L∂b\frac{\partial L}{\partial b}∂b∂L​ .
  3. Describe (and optionally write pseudocode for) how to train aaa and bbb using SGD (or mini-batch SGD):
    • parameter initialization
    • per-step gradient computation
    • update rule
    • learning rate choice / scheduling
    • stopping criteria
  4. Discuss common pitfalls and edge cases (e.g., scaling, divergence, choosing batch size).

Output / Expected Result

After training, return the learned parameters aaa and bbb that approximately minimize the chosen loss on the provided data.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Machine Learning•More Amazon•More Machine Learning Engineer•Amazon Machine Learning Engineer•Amazon Machine Learning•Machine Learning Engineer Machine Learning
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.