Implement logistic regression from scratch: sigmoid activation, binary cross-entropy loss, gradient descent with regularisation, decision boundary, precision/recall/F1 metrics, and a confusion matrix — applied to classifying Microsoft products as "premium" (price > $500) or "budget".
Background
Logistic regression applies a sigmoid function to the linear output: σ(z) = 1/(1+e⁻ᶻ), squashing any real number to (0,1) as a probability. The loss function is binary cross-entropy: -[y·log(ŷ) + (1-y)·log(1-ŷ)]. This punishes confident wrong predictions extremely harshly (log(0)→∞). L2 regularisation (λ·w²) prevents overfitting by penalising large weights.
Time
30 minutes
Prerequisites
Lab 01 (Linear Regression)
Tools
Docker: zchencow/innozverse-python:latest
Lab Instructions
💡 Binary cross-entropy is asymmetric in a crucial way. If the true label is 1 and you predict 0.99, the loss is -log(0.99)≈0.01 — tiny. But if you predict 0.01, the loss is -log(0.01)≈4.6 — massive. This "confident wrong" penalty is intentional: it forces the model to be well-calibrated. An MSE loss would let the model be 50% wrong without much penalty. This is why cross-entropy is always used for classification.