Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

L2-Regularized Logistic Regression Solver

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

Your question is L2-Regularized Logistic Regression Solver. 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 a feature matrix X of shape n x d, a binary label vector y of length n, a regularization strength lam, a learning rate lr, and a number of iterations steps, derive and implement batch gradient descent for L2-regularized logistic regression. Return the learned weight vector and bias after minimizing the regularized negative log-likelihood.

Constraints

  • 1 <= n <= 10^3
  • 1 <= d <= 50
  • X[i][j] is a real number with absolute value at most 10^3
  • y[i] is either 0 or 1
  • 0 <= lam <= 10^3
  • 0 < lr <= 1
  • 1 <= steps <= 10^5

Function Signature

def train_logistic_regression(X, y, lam, lr, steps):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output