bugger.
All challenges/Pythoneasyllm-linear-regression-v1
THE INVESTIGATION

Linear regression and MSE gradients

Fit a linear model using full-batch mean squared error.

LLM ArchitectureML foundations

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

01 Learn slope and intercept
{"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}
02 Zero requested updates
{"x":[[2]],"y":[3],"weights":[1],"bias":0,"learning_rate":0.2,"steps":0}
{"weights":[1],"bias":0,"predictions":[2],"loss":1}
03 Already fits the data
{"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.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.