Statistics and Estimation
Fitting a model is estimating parameters from a finite sample — and every estimate comes with uncertainty about how wrong it might be. This page derives maximum likelihood estimation, the principle underlying nearly every loss function used in this knowledge base, and shows the bridge from "most likely parameters" to "squared error" and "cross-entropy."
Nearly every loss function in ML is a negative log-likelihood in disguise.

Population vs. sample
The population is the entire (often infinite, unobservable) set of things you care about; the sample is the finite subset you actually observed. Every statistic computed from a sample is an estimate of some population quantity, not the quantity itself.
Estimators: bias, variance, consistency
An estimator is a function of the sample used to guess a population parameter .
- Bias: — systematic error, present even with infinite data of the same sample size.
- Variance: how much fluctuates across different samples.
- Consistency: as sample size .
Maximum likelihood estimation
Given a model family and observed data (assumed i.i.d.), the likelihood is how probable the data is under a given :
MLE picks the that makes the observed data most probable: . In practice you maximise the log-likelihood instead (same maximiser, numerically stable, turns a product into a sum):
MLE for a Gaussian, derived
Assume . The log-likelihood is:
Setting gives — the sample mean. Setting gives — the (biased) sample variance.
MLE for Bernoulli
For with : , maximised at — the observed fraction of ones.
From MLE to squared error and cross-entropy
This is the key bridge. If you assume regression targets have Gaussian noise, , maximising the log-likelihood over 's parameters is exactly minimising — squared error. If you assume a Bernoulli output for classification, maximising the log-likelihood over the model's parameters is exactly minimising binary cross-entropy. The loss functions in Loss Functions are not arbitrary choices — they are MLE under specific noise assumptions.
| Symbol | Meaning |
|---|---|
| likelihood of the data given parameters | |
| log-likelihood | |
| the maximum likelihood estimate |
MAP and priors
Maximum a posteriori adds a prior belief over parameters before seeing data: . A Gaussian prior on weights, worked through, produces exactly the L2 regularisation term in Overfitting and Regularization — regularisation is MAP estimation with a specific prior.
Confidence intervals and bootstrap
A confidence interval expresses the estimate's uncertainty: "the true value is in this range, with this confidence, under repeated sampling." The bootstrap estimates this without any distributional assumption: resample the data (with replacement) many times, recompute the statistic each time, and use the spread of results as the uncertainty estimate.
Hypothesis testing, honestly
A p-value is the probability of seeing data this extreme if the null hypothesis were true — it is not the probability the null hypothesis is true, and repeated testing without correction inflates false positives. In ML practice, hypothesis tests appear most often in A/B testing (see Online Evaluation and A/B Testing); treat p-value thresholds as one input to a decision, not a verdict.
Code: MLE by hand, and a bootstrap confidence interval
import numpy as np
rng = np.random.default_rng(0)
data = rng.normal(loc=5.0, scale=2.0, size=200)
# --- MLE for a Gaussian, by hand vs. NumPy ---
mu_hat = data.sum() / len(data)
sigma2_hat = ((data - mu_hat) ** 2).sum() / len(data)
print(f"hand-derived MLE: mu={mu_hat:.3f}, sigma^2={sigma2_hat:.3f}")
print(f"numpy: mu={data.mean():.3f}, sigma^2={data.var():.3f}")
# --- Bootstrap confidence interval for a model's accuracy ---
def fake_model_accuracy(sample):
"""Stand-in for a real evaluation metric computed on a resampled test set."""
return (sample > 4.5).mean()
n_boot = 2000
boot_scores = np.array([
fake_model_accuracy(rng.choice(data, size=len(data), replace=True))
for _ in range(n_boot)
])
lo, hi = np.percentile(boot_scores, [2.5, 97.5])
print(f"bootstrap 95% CI for the metric: [{lo:.3f}, {hi:.3f}]")
See also
- Loss Functions — where MLE cashes out into the losses actually trained against.
- Probability and Distributions — the distributions MLE is estimating parameters for.