Sign in to track progress, unlock prep layers, and browse your pipeline.Sign in
Implement Linear Regression Training
Problem Description
Implement a function train_linear_regression(X, y, lr, epochs) to train a linear regression model from scratch using batch gradient descent.
Requirements
Xis ann x dmatrix of real-valued features.yis a length-nvector of real-valued targets.- Initialize all weights (
w) and the bias (b) to0. - On each epoch, compute predictions
y_hat = Xw + b. - Utilize Mean Squared Error (MSE) as the loss function.
- Compute the gradients for
wandbwith respect to the MSE loss. - Update parameters (
wandb) using the provided learning rate (lr). - Return the final weight vector (
w) and bias (b).
Constraints
- Do not use any library routines that directly fit a regression model (e.g.,
sklearn.linear_model.LinearRegression). - Basic matrix and array operations (e.g., dot product, element-wise operations, transposing) are explicitly allowed.
AI interview prep
Core dilemma
Ensuring numerical stability and computational efficiency of gradient descent while correctly implementing the underlying linear algebra and calculus for parameter updates.
Mid-level signals3
Senior signals3
Red flags3
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement Linear Regression Training
Problem Description
Implement a function train_linear_regression(X, y, lr, epochs) to train a linear regression model from scratch using batch gradient descent.
Requirements
Xis ann x dmatrix of real-valued features.yis a length-nvector of real-valued targets.- Initialize all weights (
w) and the bias (b) to0. - On each epoch, compute predictions
y_hat = Xw + b. - Utilize Mean Squared Error (MSE) as the loss function.
- Compute the gradients for
wandbwith respect to the MSE loss. - Update parameters (
wandb) using the provided learning rate (lr). - Return the final weight vector (
w) and bias (b).
Constraints
- Do not use any library routines that directly fit a regression model (e.g.,
sklearn.linear_model.LinearRegression). - Basic matrix and array operations (e.g., dot product, element-wise operations, transposing) are explicitly allowed.