Skip to content
AI360XpertBeta
Playgrounds

Supervised Learning

Logistic Regression & Decision Boundaries

Change the classification threshold and watch its decision boundary move across the probability surface.

Data seed 12345

Guided steps 1 / 3

Stage 1 of 3: The probability field

Model weights w1 1.50, w2 -1.50, bias 0.00, with the threshold at 0.50. Log loss 1.246 over 60 points (30 positive, 30 negative).

  • Positive Class
  • Negative Class
  • Decision Boundary
  • Field: probability at least 0.5
  • Field: probability below 0.5

x₁ 1.915, x₂ 2.598; z -1.025, p 0.264, prediction negative, loss 1.331.

Adjust parameters

Controls how x₁ influences the probability.

Controls how x₂ influences the probability.

Shifts the probability field independently of the input features.

Exploratory population: 60 synthetic observations, 30 of each label. No fitting or held-out test. The boundary handle is available when the contour crosses the plot; the intercept slider always provides a keyboard equivalent.

Log Loss1.246Log Loss: 1.246

How do weights turn two features into a probability?

The model does not output discrete classes; it outputs a continuous probability field from near 0 to near 1; these manual scores are not verified as calibrated.

Logit

The weighted feature sum plus the intercept; its sigmoid gives the model probability.

Check this stage

A visual exploration of how logistic regression creates a continuous probability field rather than a hard boundary.

The surface shows a model's probability output for each pair of features. The line shows the chosen decision threshold. Changing the threshold moves the decision without changing the model's scores.

From features to a probability

The model adds the weighted features and intercept to make a logit, then applies the sigmoid. For example, with weights 2 and −1, intercept 1, and features 0 and 2, the logit is 1 + 2 × 0 − 1 × 2 = −1. The sigmoid gives approximately 0.269. At a threshold of 0.5 the decision is negative; at 0.2 it is positive.

p=11+e−(w1x1+w2x2+b)p = \frac{1}{1 + e^{-(w_1x_1 + w_2x_2 + b)}}

Change the weights and intercept and inspect an observation. These parameters are set by hand, not fitted. A number between zero and one is a model probability, but it is not evidence of calibration. Checking calibration requires comparing scores with observed frequencies on suitable independent data.

A decision is a separate choice

A point is predicted positive when its score is greater than or equal to the threshold. The boundary is the contour where the score equals that threshold. The field's texture changes at probability 0.5; this describes the score, while the line follows the selected threshold. If both weights are zero, the score is constant and there is no ordinary boundary line.

Read the counts together

The histogram, confusion counts and ROC use the same 60 synthetic observations. They are an exploratory population, not an independent test set. Log loss averages the per-observation binary cross-entropy and does not change when only the threshold moves. A high accuracy can hide missed positives, especially with imbalanced classes. Precision is undefined when no examples are predicted positive. Threshold choice depends on the costs of different mistakes, and selecting a threshold on these observations does not establish performance on new data.

In a fitted model, complete separation can prevent a finite unregularised maximum-likelihood estimate. This scene does not fit coefficients, so it does not demonstrate optimiser convergence or coefficient growth.

Stage recap

  1. The probability field

    The model does not output discrete classes; it outputs a continuous probability field from near 0 to near 1; these manual scores are not verified as calibrated.

  2. The decision contour

    The decision boundary is simply the contour line where the probability equals the chosen threshold (usually 0.5).

  3. Evaluation metrics

    Moving the threshold slides the boundary. Watch how it changes the confusion matrix and traces the ROC curve.

Reference

Sigmoid
1 / (1 + exp(-z)), squashes any real number into the (0, 1) range.
Log Loss (Cross-Entropy)
Penalises confident wrong predictions logarithmically.
Decision Boundary
The set of points where the model predicts exactly the threshold probability.
Gradient
∂L/∂wⱼ = (1/n) · Σ (p − y)·xⱼ — the same shape as linear regression, with p in place of ŷ
Threshold vs boundary
For nonzero weights, the threshold shifts the boundary without changing probabilities or refitting. Precision and recall depend on the observations.
Precision / Recall
precision = TP / (TP + FP) — of those flagged, how many were right. recall = TP / (TP + FN) — of those that mattered, how many were caught

Break it on purpose

A constant low score predicts every observation negative and misses every positive. Accuracy alone hides which class was missed.