FunctionRacerProblemsRace

Logistic Regression

HardPyTorchPython

Train a logistic regression by gradient descent. There is one weight per column of X and one bias, all starting at 0. The score of an example is its row of X times the weights, plus the bias, and the loss is the binary cross-entropy of those scores against y (zeros and ones), averaged over the examples. Take steps steps with torch.optim.SGD and learning rate lr. Return the weights followed by the bias, as one 1-D tensor.

Example 1

X [[0.0],[1.0],[2.0],[3.0]]
y [0.0,0.0,1.0,1.0]
lr 0.5
steps 10
returns [0.8601177930831909,-0.6169396638870239]

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More PyTorch problems