Linear regression gradient step
Perform one full-batch gradient-descent update step for simple linear regression y = w*x + b under mean-squared error. Given parallel lists xs and ys (n>=1 points), current weight w, bias b, and learning rate lr, compute predictions p_i = w*x_i + b, the error e_i = p_i - y_i, the gradients dw = (2/n)*sum(e_i*x_i) and db = (2/n)*sum(e_i), then return the updated parameters [w - lr*dw, b - lr*db]. Round each returned parameter to 6 decimal places.
Implement
gd_step(xs: list[float], ys: list[float], w: float, b: float, lr: float) → list[float]Examples
in
[[1,2],[2,4],0,0,0.1]out[1,0.6]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 30 min
solution.py
InputExpectedGot
[[1,2],[2,4],0,0,0.1][1,0.6]not run yetsample