bugger.
All challenges/Pythonmediumllm-logistic-regression-v1
THE INVESTIGATION

Logistic regression from scratch

Fit binary logistic regression with full-batch gradient descent.

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 feature matrix, y contains binary labels, weights and bias are initial parameters, and learning_rate and steps control batch updates. Each update averages gradients across examples, using the same pre-update parameters for both gradients. Return weights, bias, probabilities in input order, and mean binary cross-entropy loss after the final update. Evaluate sigmoid and loss stably for extreme finite logits.

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 binary logistic regression with full-batch gradient descent.

Reproduction

01 Opposing features learn a positive weight
{"x":[[-1],[1]],"y":[0,1],"weights":[0],"bias":0,"learning_rate":1,"steps":2}
{"weights":[0.877541],"bias":0,"probabilities":[0.293688,0.706312],"loss":0.347698}
02 Untrained zero logits
{"x":[[4]],"y":[1],"weights":[0],"bias":0,"learning_rate":0.2,"steps":0}
{"weights":[0],"bias":0,"probabilities":[0.5],"loss":0.693147}
03 Bias learns with zero features
{"x":[[0],[0]],"y":[1,1],"weights":[0],"bias":0,"learning_rate":1,"steps":1}
{"weights":[0],"bias":0.5,"probabilities":[0.622459,0.622459],"loss":0.474077}

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.