We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
← Build a Decision Boundary step 1 of 1
Decision Boundary Lab
Your project
Build a binary classifier from its training loop up. On the featured dataset, your returned weights draw a decision boundary and your loss history becomes a learning curve. Export your work as a script to run and adapt on your machine.
Before you start: matrix-vector multiplication, sigmoid, and mean binary cross-entropy. The Binary Classifier and Train Binary Classifier exercises are useful preparation. Here you add a learned bias and record the training history.
1. Make predictions
For x of shape (N, 2), initialise w of shape (2,) and scalar b to zero.
Compute logits = x @ w + b and p = sigmoid(logits).
A probability of at least 0.5 predicts class 1.
2. Measure the error
Record the mean BCE before training and after each update. Use the stable
expression max(z, 0) - y*z + log1p(exp(-abs(z))) for each logit z.
This is BCE from logits; do not add an epsilon or threshold probabilities
before computing the loss.
3. Learn a boundary
Apply full-batch gradient descent:
error = p - y, dw = x.T @ error / N, db = mean(error).
Update both parameters using the same pre-update errors:
w = w - lr*dw, b = b - lr*db.
No optimiser object, mini-batches, regularisation or random initialisation is needed.
Return contract
Return a dictionary with ordinary Python values:
-
weights: a list of two floats. -
bias: a float. -
losses: a list ofsteps + 1floats, including the initial loss. Inputs are non-empty float32 tensors; labels are 0 or 1.stepsis a nonnegative integer andlris nonnegative. Do not mutate the inputs. With zero steps, return zero parameters and just the initial loss.
Worked example
For x=[[1, 0]], y=[1], steps=1, lr=0.2, the initial probability is
0.5. The gradients are dw=[-0.5, 0] and db=-0.5, so the result is
weights=[0.1, 0.0], bias=0.1, losses≈[0.693147, 0.598139].
Read your results
Run the visible cases to draw the featured dataset. Class 0 and class 1 use different point shapes. The shaded regions show predictions from your returned parameters. The chart is training fit, not evidence of generalisation: the exported script also evaluates a separate, fixed holdout set. A boundary is absent when both weights are zero; the model predicts one probability everywhere. Submit to check the remaining edge cases.
Stuck?
PyTorch reference solution
Sign in to attempt this problem and reveal the reference solution.