Logistic regression turns a linear score into a probability between 0 and 1. It is the default first model for binary classification — and the sigmoid that powers it is the same curve sitting at the end of countless neural nets.
Where you meet it
- Spam / not-spam, click / no-click, fraud / legit — any yes-or-no prediction.
- Credit scoring and medical risk: "probability this patient has the condition".
- The final layer of a neural network, where
sigmoidoutputs a class probability.
What it does
Linear regression predicts an unbounded number. That is useless for a yes/no question — a probability has to live in 0…1. Logistic regression takes the same linear score and bends it through the sigmoid so the output is always a valid probability, then thresholds it into a decision.
It says "regression" but it classifies, and that famous 0.5 cutoff is just a default — move it the moment your costs aren't symmetric.
How it works
First compute a linear score (the logit), then squash it with the sigmoid:
z = w·x + b # linear score
σ(z) = 1 / (1 + e^−z) # squash into (0, 1)
ŷ = 1 if σ(z) ≥ 0.5 # decide
The sigmoid is an S-curve: very negative z → 0, very positive → 1, and z = 0 gives exactly 0.5. So the decision boundary is wherever z = 0, i.e. w·x + b = 0 — the dashed line in the tool. The weight sets how steep the S is: a bigger weight means a sharper, more confident jump from 0 to 1.
Training picks w and b by minimising log-loss (binary cross-entropy), not mean squared error:
L = −[ y·log(σ) + (1−y)·log(1−σ) ]
This penalises a confident wrong answer heavily and is convex in the parameters, so gradient descent reliably finds the best fit.
Watch out
- It is classification, not regression. The "regression" in the name refers to the linear score inside — the output is a class probability.
- Don't train with MSE. Squared error over the sigmoid is non-convex and flattens out (vanishing gradients); cross-entropy is the right loss.
- 0.5 is not sacred. On imbalanced data or asymmetric costs, move the threshold — for a rare disease you may flag at 0.1, not 0.5.
- The boundary is linear. Plain logistic regression separates classes with a straight line/plane; for curved boundaries you need feature engineering or a richer model.
Go deeper
- scikit-learn — Logistic Regression (user guide, log-loss & "classifier despite the name")
- An Introduction to Statistical Learning (ISL) — free PDF, Classification chapter
- Stanford CS229 — main lecture notes (logistic regression & the sigmoid, PDF)
- Jurafsky & Martin, SLP3 Ch. 5 — Logistic Regression & cross-entropy (PDF)
Logistische Regression macht aus einem linearen Score eine Wahrscheinlichkeit zwischen 0 und 1. Sie ist das Standard-Erstmodell für binäre Klassifikation — und das Sigmoid dahinter ist genau die Kurve, die am Ende unzähliger neuronaler Netze sitzt.
Wo es vorkommt
- Spam / kein Spam, Klick / kein Klick, Betrug / legitim — jede Ja-Nein-Vorhersage.
- Kredit-Scoring und medizinisches Risiko: "Wahrscheinlichkeit, dass dieser Patient die Krankheit hat".
- Die letzte Schicht eines neuronalen Netzes, wo
sigmoideine Klassenwahrscheinlichkeit ausgibt.
Was es tut
Lineare Regression sagt eine unbeschränkte Zahl vorher. Für eine Ja-Nein-Frage ist das nutzlos — eine Wahrscheinlichkeit muss in 0…1 liegen. Logistische Regression nimmt denselben linearen Score und biegt ihn durchs Sigmoid, sodass die Ausgabe immer eine gültige Wahrscheinlichkeit ist, und macht daraus per Schwelle eine Entscheidung.
Sie heißt Regression, klassifiziert aber — und der berühmte 0.5-Schnitt ist nur ein Default: verschieb ihn, sobald die Kosten nicht symmetrisch sind.
Wie es funktioniert
Zuerst ein linearer Score (das Logit), dann gestaucht durchs Sigmoid:
z = w·x + b # linearer Score
σ(z) = 1 / (1 + e^−z) # stauchen auf (0, 1)
ŷ = 1 falls σ(z) ≥ 0.5 # entscheiden
Das Sigmoid ist eine S-Kurve: stark negatives z → 0, stark positives → 1, und z = 0 ergibt genau 0.5. Die Entscheidungsgrenze liegt also dort, wo z = 0, also w·x + b = 0 — die gestrichelte Linie im Tool. Das Gewicht bestimmt die Steilheit des S: größeres Gewicht heißt ein schärferer, sichererer Sprung von 0 auf 1.
Das Training wählt w und b, indem es den Log-Loss (binäre Kreuzentropie) minimiert, nicht den mittleren quadratischen Fehler:
L = −[ y·log(σ) + (1−y)·log(1−σ) ]
Das bestraft eine selbstsichere Fehlentscheidung hart und ist konvex in den Parametern — Gradientenabstieg findet so zuverlässig die beste Anpassung.
Worauf achten
- Es ist Klassifikation, keine Regression. Das "Regression" im Namen meint den linearen Score im Inneren — die Ausgabe ist eine Klassenwahrscheinlichkeit.
- Nicht mit MSE trainieren. Quadratischer Fehler über dem Sigmoid ist nicht-konvex und flacht ab (verschwindende Gradienten); Kreuzentropie ist der richtige Loss.
- 0.5 ist nicht heilig. Bei unbalancierten Daten oder asymmetrischen Kosten verschiebt man die Schwelle — bei einer seltenen Krankheit warnt man vielleicht schon ab 0.1, nicht erst ab 0.5.
- Die Grenze ist linear. Schlichte logistische Regression trennt Klassen mit einer Gerade/Ebene; für gekrümmte Grenzen braucht es Feature-Engineering oder ein reicheres Modell.
Mehr dazu
- scikit-learn — Logistic Regression (User Guide, Log-Loss & "Klassifikator trotz des Namens")
- An Introduction to Statistical Learning (ISL) — kostenloses PDF, Kapitel Classification
- Stanford CS229 — Vorlesungsskript (logistische Regression & Sigmoid, PDF)
- Jurafsky & Martin, SLP3 Kap. 5 — Logistische Regression & Kreuzentropie (PDF)