Linear Classifiers › Logistic Regression: From Score to Probability
Language AI HandbookAll chapters Linear Classifiers › Logistic Regression: From Score to ProbabilityOne section · Sections in this chapter5 / 16 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The raw score can be any real number, from negative infinity to positive infinity. This makes it hard to interpret as a probability, since probabilities must lie between 0 and 1. Logistic regression solves this by passing the score through the sigmoid function.
To convert into a probability, we need a function that maps to . The sigmoid function does exactly this:
where:
- : the raw linear score , any real number
- : the exponential of ; this quantity is large when is negative and small when is positive
- : the denominator, which normalizes the output
- : the resulting probability, always strictly between 0 and 1
The sigmoid function has three key properties:
- When : , so (confident positive prediction)
- When : , so (confident negative prediction)
- When : (maximum uncertainty, on the decision boundary)
The function is smooth and differentiable everywhere, a requirement for gradient descent. Its derivative also has a convenient form:
where:
- : the sigmoid output at
- : one minus the sigmoid, since
This derivative is easy to compute once you have the forward pass value, which makes backpropagation through the sigmoid efficient. You compute on the forward pass and store it; on the backward pass, you compute without any additional expensive operations.
Logistic regression applies the sigmoid function to the linear score to produce a probability estimate. It predicts , where is the sigmoid function. Despite the name "regression," it is used for classification.
def sigmoid(z):
"""Map a real-valued score to the interval (0, 1)."""
return 1.0 / (1.0 + np.exp(-z))
def logistic_predict_proba(x, w, b):
"""Return the probability of the positive class."""
z = np.dot(w, x) + b
return sigmoid(z)Review 1 (enthusiastic): Linear score: 3.60 P(positive): 0.973 Review 2 (disappointed): Linear score: -3.80 P(positive): 0.022 Review 3 (mixed): Linear score: -0.20 P(positive): 0.450
Review 1 gets a high probability of being positive. Review 2 gets a low probability. Review 3, near the decision boundary, gets a probability close to 0.5. These probabilities are more informative than a hard yes/no decision because they communicate the model's confidence. A downstream system can decide how to act based on these probabilities: it might automatically file a very high-confidence prediction but route uncertain ones to a human reviewer.
The Sigmoid Curve
Visualizing the sigmoid function helps build intuition about how it compresses scores into probabilities.

Notice how the sigmoid "saturates" in the tails: for or , the function barely changes. This saturation has consequences for training. When the classifier is very confident but wrong, the gradient of the sigmoid is tiny, meaning learning happens slowly. This is the vanishing gradient problem in its simplest form, and it is one reason why alternative activations like ReLU (covered in the Activation Functions chapter) were developed for hidden layers of deep networks. For output layers producing probability estimates, however, sigmoid and softmax remain standard.
The Log-Odds Connection
The sigmoid function has a natural probabilistic interpretation through log-odds. If , then the odds in favor of the positive class are , and the log-odds (also called the logit) are . Inverting the sigmoid relationship shows that:
This means logistic regression is modeling the log-odds of the positive class as a linear function of the input features. A unit increase in feature multiplies the odds of the positive class by . This multiplicative relationship in odds space corresponds to an additive relationship in log-odds space, which is what makes the math tractable. The log-odds framing also connects logistic regression to Naive Bayes classifiers: under a specific set of distributional assumptions (that features are conditionally independent given the class), Naive Bayes produces a classifier with the same logistic regression form, with weights determined by feature likelihood ratios.