Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Linear Regression with Gradient Descent

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Linear Regression with Gradient Descent. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given two integer arrays x and y of equal length, implement batch gradient descent for univariate linear regression. Write a function that runs a fixed number of iterations to learn parameters w and b for the model y_pred = w * x + b, and return the final [w, b] as floats.

Constraints

  • 1 <= len(x) == len(y) <= 10^4
  • -10^3 <= x[i], y[i] <= 10^3
  • 0 < learning_rate <= 1
  • 1 <= iterations <= 10^5

Function Signature

def fit_linear_regression_gd(x, y, learning_rate, iterations):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output