ML Playground
ClassificationIntermediateSupervised learning

Logistic regression

Available

Fit 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

Training points and linear decision boundary-6.8-3.20.44.07.6-3.4-0.91.64.16.6xy
80 training points. The model doesn't define a linear boundary yet (zero or degenerate weights).
  • 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%

Decision threshold: 0.5. Cross-check: 50.0%.

Precision
50.0%
Recall
100.0%
F1
66.7%

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.

40
5120
1.4

Standard deviation of each blob. Low: nearly linearly separable. High: overlapping classes.

0.34.0

Loss

Loss (log-loss) evolution per iteration0.00.30.50.81.00.00.30.50.81.0IterationLog-loss
No iterations recorded yet.

Gradient descent

0.100
0.0011.000

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).

Related concepts

References