Skip to content
StackDecode
AI & ML Atlas
Machine LearningalgorithmInteractive simulation

Logistic Regression

Predicts the probability of a yes/no outcome with an S-shaped curve.

The idea

It computes a linear score z = w·x + b and squashes it with the sigmoid to give a probability between 0 and 1. It is trained by minimising log-loss (cross-entropy), which punishes confident wrong answers heavily. Despite the name, it is a classifier.

p = 1 / (1 + e^(−z)), loss = −[y·ln p + (1−y)·ln(1−p)]

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

  • class 0
  • class 1
  • decision boundary

All weights start at zero, so every point is 50/50. There is no boundary yet.

step:
0
loss:
0.693
accuracy:
50%
1/14

The line is where the predicted probability is exactly 50%.

Step by step

  1. 1Compute the score z = w·x + b.
  2. 2Turn it into a probability with the sigmoid.
  3. 3Compare with the true label using log-loss.
  4. 4Update w and b by gradient descent.
  5. 5Classify as 1 when the probability exceeds a threshold (often 0.5).

Where it is used

Credit risk, medical diagnosis, click prediction, a strong baseline.

Watch out for

Only draws a straight decision boundary; perfectly separable data makes the weights grow without bound unless regularised.

Related