Equations · Standard statistics; Cox, “The Regression Analysis of Binary Sequences” (1958)
The logistic regression formula, explained
The simplest classifier: a linear score passed through the sigmoid to get a probability between 0 and 1. It is a one-layer neural network, and the last layer of most binary classifiers is exactly this.
Term by term
The probability that the label is 1, given the features .
A linear score (the logit): the dot product of the weights with the features, plus a bias . Its sign decides the predicted class; is the decision boundary.
Bold lowercase (vector) · Transpose · Inner product (angle brackets)
The sigmoid, squashing any real number into , with . Here is a function, not a standard deviation.
Shapes
- One example: , . A batch: , and .
A small worked example
, , : the score is , so , and the prediction is class 0. Training minimizes the binary cross-entropy, whose gradient is simply .
In code
import numpy as np
def predict_proba(X, w, b):
return 1 / (1 + np.exp(-(X @ w + b))) # (N,)
def gradients(X, y, w, b):
p = predict_proba(X, w, b)
return X.T @ (p - y) / len(y), np.mean(p - y) # d loss / dw, d loss / dbEvery symbol in it
Other equations
- Scaled dot-product attention
- Softmax
- Cross-entropy loss
- Adam update
- Layer normalization
- RMSNorm
- The ELBO
- KL divergence
- Backpropagation through one layer
- LoRA
- GELU
- Dropout
- Batch normalization
- Rotary position embedding (RoPE)
- Multi-head attention
- PPO clipped objective
- DPO loss
- Policy gradient (REINFORCE)
- Bellman equation
- Q-learning update
- InfoNCE contrastive loss
- Diffusion forward process
- DDPM simplified loss
- VAE reparameterization trick
- GAN minimax objective
- AdamW
- Cosine learning-rate schedule
- Perplexity
- Normal equation (linear regression)
- Singular value decomposition (SVD)
- Principal component analysis (PCA)