PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Machine Learning/Amazon

Implement Batch Gradient Descent for Linear Regression

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's understanding of linear regression, mean squared error, and batch gradient descent, including vectorized prediction, gradient computation, and parameter updates within the Machine Learning domain.

  • easy
  • Amazon
  • Machine Learning
  • Data Scientist

Implement Batch Gradient Descent for Linear Regression

Company: Amazon

Role: Data Scientist

Category: Machine Learning

Difficulty: easy

Interview Round: Technical Screen

##### Scenario Building a linear regression model from scratch; parameters are optimized through batch gradient descent. ##### Question Write Python-style pseudocode for batch gradient descent that minimizes mean-squared error for linear regression. Explain briefly what each step in your pseudocode does. ##### Hints Cover initialization, prediction, error, gradient, parameter update, loop/stop conditions.

Quick Answer: This question evaluates a candidate's understanding of linear regression, mean squared error, and batch gradient descent, including vectorized prediction, gradient computation, and parameter updates within the Machine Learning domain.

Related Interview Questions

  • Explain Transformer and MoE Fundamentals - Amazon (medium)
  • 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)
Amazon logo
Amazon
Jul 12, 2025, 6:59 PM
Data Scientist
Technical Screen
Machine Learning
14
0

Batch Gradient Descent for Linear Regression (MSE)

Scenario

You are building a linear regression model from scratch and will optimize its parameters using batch gradient descent.

Assume you have:

  • Feature matrix X \in R^{n \times d} (n samples, d features)
  • Target vector y \in R^{n}
  • A weight vector w \in R^{d} and a scalar bias b (intercept)

Task

Write Python-style pseudocode for batch gradient descent that minimizes mean squared error (MSE) for linear regression. Briefly explain what each step in your pseudocode does.

Your pseudocode should cover:

  1. Initialization of parameters (w, b)
  2. Vectorized prediction
  3. Error and loss (MSE)
  4. Gradient computation
  5. Parameter updates
  6. Looping and stopping conditions (e.g., max iterations, tolerance)

Solution

Show

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Machine Learning•More Amazon•More Data Scientist•Amazon Data Scientist•Amazon Machine Learning•Data Scientist Machine Learning
PracHub

Master your tech interviews with 8,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.