Concepts 🚀 Project 🧮 Labs
🧮 Labs / ML Advanced / Logistic Regression visualized — sigmoid + decision boundary (iris)

Logistic Regression visualized — sigmoid + decision boundary (iris)

SEE the sigmoid curve, SEE the decision boundary move as you change C. Uses the iris dataset. The maths becomes obvious when you can visualize it.

script.py v3.1
Python output click Run to execute
Click "Run" to execute the code on the left.
The output will appear here.
🧠 How it works

Logistic Regression maths — VISUALIZED: SIGMOID: σ(z) = 1/(1+e^(-z)). Squashes any number to [0, 1] = probability. At z=0, σ=0.5 (the decision boundary). z > 0 → σ > 0.5 → predict class 1. z < 0 → σ < 0.5 → predict class 0. DECISION BOUNDARY: the LINE where z = β₀ + β₁x₁ + β₂x₂ = 0. Everything on one side = class 0, other side = class 1. For 3 classes (iris): 3 binary classifiers (one-vs-rest), boundaries intersect. C PARAMETER (inverse regularization): C=1.0 (default): balanced. C=0.01: strong regularization → simpler boundary → might underfit. C=100: weak regularization → complex boundary → might overfit. KEY INSIGHT: logistic regression is LINEAR — the boundary is always a straight line (or hyperplane). If classes aren't linearly separable, it fails. That's why iris setosa (easily separable) gets 100% accuracy but versicolor/virginica overlap.

✏️ Try these changes
  • Change C from 1.0 to 0.01
    → strong regularization → simpler boundary, might misclassify more
  • Change C from 1.0 to 100
    → weak regularization → boundary fits tighter, might overfit
  • Use sepal features instead: X = iris.data[:, [0, 1]]
    → different feature pair — setosa still separable, but versicolor/virginica overlap more
  • Add max_iter=2000 to the model (some convergences need more iterations)
    → fixes convergence warnings