The logit is a function that transforms a probability , with , into the natural logarithm of its odds:
It maps the open interval onto the real numbers, and its inverse is the standard logistic function. The transformation is central to logistic regression. (docs.scipy.org)
Definition and interpretation
The odds of an event with probability are : the probability that the event occurs divided by the probability that it does not occur. Taking the natural logarithm converts these positive odds into an unrestricted real-valued quantity. Odds and probabilities are different quantities; for example, a probability of corresponds to odds of , or , and a logit of . (online.stat.psu.edu)
Some representative values are:
| Probability | Odds | Logit |
|---|---|---|
Thus, a negative logit represents a probability below one-half, while a positive logit represents a probability above one-half. These values follow directly from the definition. (docs.scipy.org)
The real-valued function is undefined at and , but its limiting values are
Numerical implementations may return these infinities at the endpoints. (docs.scipy.org)
Inverse and mathematical properties
Solving for gives the inverse function:
This function is also called the logistic sigmoid or expit. The logit converts a probability into log-odds; the sigmoid converts log-odds back into a probability. (docs.scipy.org)
The derivative of the logit is
Consequently, it is strictly increasing. The derivative grows without bound near either endpoint, so a small change in probability near zero or one can correspond to a large change in log-odds. (statsmodels.org)
Two further properties follow algebraically from the definition:
and
The first expresses symmetry under exchanging an event with its complement. The second shows that a difference in logits is the logarithm of an odds ratio. (docs.scipy.org)
Logistic regression
Binary logistic regression models the conditional probability of an outcome through
The right-hand side is the linear predictor. Applying the inverse logit produces a fitted probability strictly between zero and one for every finite predictor value. The model is linear in log-odds, not in probability. (online.stat.psu.edu)
In this additive model, increasing by one unit while holding the other predictors fixed changes the log-odds by , and therefore multiplies the odds by . This does not imply a constant change in probability: the probability change depends on the starting value of the linear predictor. (online.stat.psu.edu)
Logits in machine learning
In machine learning, particularly neural networks, logits also denotes real-valued scores before conversion to probabilities. In binary classification, a score passed through the sigmoid satisfies
This usage therefore agrees exactly with the mathematical definition when the associated probability is the sigmoid output. (tensorflow.org)
For mutually exclusive classes, the term has a broader meaning. Scores are commonly called logits and converted into probabilities using the softmax function:
A score is not generally the binary logit . Instead, algebraic cancellation yields
Adding the same constant to every score leaves all probabilities unchanged. With two classes, the difference equals . (docs.pytorch.org)
Loss computation and numerical stability
For a binary target and predicted probability , the binary cross-entropy loss can be expressed directly in terms of the logit:
An equivalent numerically stable form is
This avoids exponentiating a large positive number. (tensorflow.org)
Computing the loss directly from logits also avoids some numerical stability problems associated with calculating sigmoid probabilities and their logarithms separately. Libraries such as PyTorch provide combined sigmoid-and-cross-entropy operations for this purpose. (docs.pytorch.org)
References
- scipy.special.logit — SciPy Manualdocs.scipy.org
- statsmodels.genmod.families.links.Logit.derivstatsmodels.org
- CrossEntropyLoss — PyTorch documentationdocs.pytorch.org
- tf.nn.sigmoid_cross_entropy_with_logits — TensorFlowtensorflow.org
- BCEWithLogitsLoss — PyTorch documentationdocs.pytorch.org