Notes

Sigmoid (Logistic) Function

When a model produces any real number—like 3.7 or -12.4—but you need a clean “probability of yes” between 0 and 1, you need a smooth way to squash that number into a probability-like scale. The sigmoid (logistic) function is the standard tool for doing exactly that.

What it is and what it does

The sigmoid maps a real-valued input z to a value between 0 and 1 using:

σ(z) = 1 / (1 + exp(-z))

It has an S-shape: large positive z becomes close to 1, large negative z becomes close to 0, and z = 0 maps to 0.5. In logistic regression, the model first computes a linear score z = w·x + b, then applies the sigmoid to get P(y=1 | x).

Why logistic regression relies on it

The sigmoid isn’t just a convenient squashing function; it connects linear scores to probability in a way that makes training well-behaved. Specifically, it implies that the log-odds are linear: log(p/(1-p)) = w·x + b. That relationship leads directly to the standard maximum likelihood training objective (cross-entropy / log loss), which is convex for logistic regression and supports stable optimization.

Practical intuition and examples

  • Spam detection: a high linear score from spammy words pushes σ(z) toward 1 (spam probability).
  • Credit approval: risk-related features push σ(z) toward 0 or 1, giving an interpretable probability of default.
  • Medical diagnosis: σ(z) provides calibrated-ish probabilities that can be thresholded (e.g., treat if > 0.8).

In scikit-learn, LogisticRegression uses this link internally; predict_proba returns the sigmoid-transformed probabilities for binary classification.

The Sigmoid (Logistic) Function is the nonlinear mapping σ(z)=1/(1+e−z) that converts any real-valued score into a value in (0,1), interpretable as a probability. In logistic regression, it transforms the linear predictor w·x+b into P(y=1|x), enabling probabilistic classification and maximum-likelihood training; without it, the model cannot produce calibrated class probabilities or a proper log-loss objective.

Think of a dimmer switch instead of a simple on/off light switch. As you turn the knob, the brightness doesn’t jump instantly from dark to bright—it changes smoothly. The Sigmoid (Logistic) Function is like that dimmer for AI decisions: it takes a raw score and smoothly squeezes it into a range between 0 and 1.

That 0-to-1 output is easy to read as a probability. For example, a spam filter might output 0.95 (very likely spam) or 0.10 (probably not). In logistic regression, this function is what turns “evidence” from the data into a clear, probability-style prediction.