Math toolkit
Maximum likelihood
Maximum likelihood picks the parameters that make the data you saw most probable. Squared error and cross-entropy are both this one idea.
Training a model means choosing its parameters. Maximum likelihood estimation (MLE) asks one question: which parameter values make the data we actually saw most probable? The answer to that question gives you the two losses you will use most.
Concept
The likelihood L(θ; data) = P(data | θ) holds the data fixed and asks which θ makes it most probable. MLE picks θ̂ = argmax L. In practice you maximize the log-likelihood, which has the same maximizer and is easier to compute.
Walking through a coin
You flip a coin 10 times and get 7 heads. Which heads probability p makes that most likely?
The probability of exactly this sequence is p⁷ · (1 − p)³. Taking logs gives:
log L(p) = 7 · ln(p) + 3 · ln(1 − p)
d/dp: 7/p − 3/(1 − p) = 0
7(1 − p) = 3p
p = 0.7The MLE is the observed fraction of heads, 7 out of 10. Nothing else was needed.
Why squared error is MLE
Assume each label is the model's prediction plus Gaussian noise: yᵢ = f_θ(xᵢ) + εᵢ, with εᵢ ~ Normal(0, σ²). The log-likelihood of the data is:
log likelihood = constant − (1 / 2σ²) · Σᵢ (yᵢ − f_θ(xᵢ))²Maximizing that means minimizing the sum of squared errors. Squared loss is not an arbitrary default. It is MLE when the noise is Gaussian.
Why cross-entropy is MLE
For a classifier, the model gives a probability p_θ(y | x) for each class. Maximizing the log-likelihood of the labels:
maximize Σᵢ log p_θ(yᵢ | xᵢ)
equals minimize −Σᵢ log p_θ(yᵢ | xᵢ) (cross-entropy)Softmax is how the model produces that categorical distribution. See softmax and temperature.
Why we use logs
Multiplying many probabilities gives a number too small for a float32 to hold. The log turns that product into a sum:
0.01 · 0.02 · 0.03 = 0.000006 (6 × 10⁻⁶)
ln 0.01 + ln 0.02 + ln 0.03 = −4.605 − 3.912 − 3.507 = −12.024
exp(−12.024) ≈ 6.0 × 10⁻⁶Same answer, and the sum still works when you have hundreds of terms.
Common mistakes
- Maximizing likelihood with no safeguard. MLE can overfit small datasets. Priors and penalties help. A prior turns MLE into MAP, and L2 weight decay is a Gaussian prior on weights.
- Multiplying raw probabilities. Long products underflow to zero. Sum logs instead.
- Treating squared loss as a free choice. It is MLE only under Gaussian noise. If the noise is clearly not Gaussian, the loss needs a different justification.
Check yourself
- Why maximize the log-likelihood instead of the likelihood? Answer: the log does not move the maximizer, and sums are numerically stable.
- What is the MLE of
pafter 3 heads in 10 flips? Answer: 0.3, the observed fraction.
Key takeaways
- MLE picks the parameters that make the observed data most probable.
- Maximize the log-likelihood. The argmax is the same and the arithmetic is stable.
- Squared error is MLE under Gaussian noise. Cross-entropy is MLE for categorical outputs.
- Plain MLE can overfit. A prior turns it into MAP, which acts as regularization.
Further learning
Next, see how a softmax turns raw scores into the probabilities that cross-entropy needs, in softmax and temperature.
Related
Softmax and temperature
Softmax turns raw model scores into a probability distribution. Temperature controls how sharp or flat that distribution is.
Entropy and cross-entropy
Entropy measures how surprising a distribution is on average. Cross-entropy measures how well a model's guesses match reality, and it is the classification loss.
Linear and logistic regression
The two models under almost everything in ML. They fit lines, predict probabilities and stay honest through regularization.