Linear regression and MSE gradients
Fit a linear model using full-batch mean squared error.
What’s going wrong
Original LLM Architecture lab. Implement the missing behavior in solve(data) and keep the supplied JSON interface. Use Python’s standard library.
Input x is a nonempty matrix, y is a list of real targets, weights and bias are initial values, and steps and learning_rate control gradient descent. Use MSE = mean((prediction − target)²), including the factor of two in its derivative. Return final weights, bias, predictions and loss.
Small, well-formed JSON inputs and standard-library Python arithmetic. Keep full precision during computation. The supplied output wrapper rounds results to six decimal places.
Expected behavior
Fit a linear model using full-batch mean squared error.
Reproduction
{"x":[[0],[1]],"y":[1,3],"weights":[0],"bias":0,"learning_rate":0.2,"steps":2}{"weights":[0.92],"bias":1.16,"predictions":[1.16,2.08],"loss":0.436}{"x":[[2]],"y":[3],"weights":[1],"bias":0,"learning_rate":0.2,"steps":0}{"weights":[1],"bias":0,"predictions":[2],"loss":1}{"x":[[1],[2]],"y":[2,4],"weights":[2],"bias":0,"learning_rate":0.1,"steps":3}{"weights":[2],"bias":0,"predictions":[2,4],"loss":0}Before you begin
- Python functions, lists and dictionaries
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.