Logistic regression
AvailableFit a linear boundary that separates two classes and watch the log loss evolve.
Description
Qué haceDraws a line that separates two classes and computes, for any point, the probability of belonging to each side of that line.
Para qué sirveClassify into two categories (spam/not spam, approve/reject, click/no click) when, beyond the label, you also care how confident the prediction is.
Draws a linear boundary that separates two classes and predicts the probability of belonging to each one. Synthetic dataset, with a deterministic seed.
From a line to a probability
Linear combination
z = w₁·x + w₂·y + b
The same boundary the playground draws when z = 0.
Sigmoid
σ(z) = 1 / (1 + e⁻ᶻ)
Squashes z into a probability in (0, 1). At z = 0, σ(z) = 0.5.
Training:Gradient descent on the log-loss (binary cross-entropy); the gradient has the same shape as in linear regression: (prediction − actual) · feature. It stops after 500 iterations or an improvement < 1e-7.
How the fit is measured
Log-loss
-[y·log(p) + (1-y)·log(1-p)]
Penalizes a confident, wrong prediction more heavily. 0 is a perfect fit.
Accuracy, precision, recall, F1
With a 0.5 threshold over the confusion matrix for the whole visible dataset (details in fundamentals).
Compared to KNN and the decision tree
Assumes linear separability
Raise the blob spread: once they overlap, the log-loss stalls instead of dropping — unlike KNN or the decision tree, which draw curved boundaries.
Compact model
Just three numbers (two weights, one intercept): cheaper to evaluate than storing the whole dataset (KNN) or a tree.
Sensitive to scaling
Turn on "Scale features (z-score)" and compare iterations to convergence with the same learning rate.
Nearly separable data
Without regularization, weights can grow without bound. The demo stops training if they stop being finite and flags it as divergence.
Playground
Training
- Class 0
- Class 1
The solid line is the decision boundary (w·x + b = 0). Points with a red ring are misclassified by the current model and threshold.
Current model metrics (gradient descent)
- Weight x
- 0.000
- Weight y
- 0.000
- Intercept
- 0.000
- Log-loss
- 0.6931
- Iteration
- 0 / 500
- Accuracy
- 50.0%
- Precision
- 50.0%
- Recall
- 100.0%
- F1
- 66.7%
Decision threshold: 0.5. Cross-check: 50.0%.
Dataset generation
Two Gaussian blobs (class 0 and class 1). Changing these controls generates a new dataset and resets gradient descent.
Seed for the deterministic generator.
Standard deviation of each blob. Low: nearly linearly separable. High: overlapping classes.
Loss
Gradient descent
Too high can diverge (the loss grows or the weights stop being finite); too low converges slowly.
Status: Ready. The model starts with weights and intercept equal to zero.
Training controls are available. Shortcut: spacebar starts or pauses (if focus isn't in a text field or control).