Probability in Machine Learning

Last Updated 05 Sep, 2026

Machine learning models rarely deal with certainty. A fraud detector doesn't "know" a transaction is fraudulent — it estimates how likely it is. A translation model doesn't "know" the next word — it ranks candidates by probability. Probability is the mathematical toolkit models use to reason under uncertainty, and it shows up in almost every stage of a modern ML system: how a model outputs predictions, how it's trained, and how its confidence is measured.

A probability is always a number between 0 and 1:

P(A) = number of favorable outcomes / total number of outcomes

A coin flip gives heads with P(H) = 1/2. That's the whole idea — everything below builds on this one ratio.

Sample Spaces, Events, and Random Variables

Four building blocks define how probability is framed mathematically:

  • Sample space (S) — every possible outcome of an experiment. Rolling a die: S = {1, 2, 3, 4, 5, 6}.
  • Event — any subset of the sample space you care about. "Rolling an even number" is the event E = {2, 4, 6}.
  • Random experiment — a process with an uncertain outcome (rolling a die, flipping a coin, sampling a random user from your app's logs).
  • Random variable — a function that maps each outcome to a number, so you can do math with it. Random variables come in two flavors: discrete (countable — number of clicks on an ad, number of failed login attempts) and continuous (any value in a range — a sensor reading, a model's confidence score, response latency in milliseconds).

Sample Spaces, Events, and Random Variales

The sample space is everything that could happen; an event is the specific slice you're measuring. Every ML probability calculation — the chance an email is spam, the chance a loan defaults — is this same structure applied to messier, real-world outcomes.

The Core Rules of Probability

A handful of rules let you combine and manipulate probabilities without recomputing everything from scratch:

  • Addition rule: P(A ∪ B) = P(A) + P(B) − P(A ∩ B) — the probability that A or B happens.
  • Multiplication rule (independent events): P(A ∩ B) = P(A) · P(B) — the probability that A and B both happen, when one doesn't affect the other.
  • Complement rule: P(A′) = 1 − P(A) — the probability that A does not happen.
  • Conditional probability: P(A | B) = P(A ∩ B) / P(B) — the probability of A, given that B has already occurred. This is the rule a recommendation system uses when it asks "given that this user liked sci-fi, how likely are they to like this next movie?"
  • Bayes' theorem: P(A | B) = P(B | A) · P(A) / P(B) — flips a conditional probability around, letting a model update a belief once new evidence comes in. It's the backbone of spam filters, medical risk models, and fraud scoring, where a prior estimate gets revised as more signals arrive.

PMF, PDF, and CDF: Three Ways to Describe a Distribution

Once you have a random variable, you need a way to describe how its probability is spread across possible values. Three functions do this job, and picking the right one depends on whether your variable is discrete or continuous:

  • PMF (Probability Mass Function) — for discrete variables. It gives the exact probability of each outcome. A spam filter's output category (spam / not spam) is naturally described with a PMF.
  • PDF (Probability Density Function) — for continuous variables. It describes the relative likelihood of values across a range rather than an exact probability at a point. Anomaly detection systems fit a PDF to "normal" sensor readings, then flag anything that falls in a low-density region.
  • CDF (Cumulative Distribution Function) — the probability that a variable is less than or equal to a given value, P(X ≤ x). It's the function you reach for whenever a decision depends on a threshold — like a credit risk model asking "what's the probability this applicant's score falls below the safe cutoff?"

PMF, PDF, and CDF: Three Ways to Describe a Distribution

Same underlying idea, three different jobs: PMF answers "what's the probability of exactly this value," PDF answers "how densely packed are values around this point," and CDF answers "what's the probability of being at or below this value" — the one threshold-based decisions actually use.

Probability Distributions Models Are Built On

A probability distribution is a specific mathematical shape describing how likely different outcomes are. A handful of them cover most of applied ML:

  • Bernoulli — a single yes/no trial (a spam classifier's raw output for one email).
  • Binomial — the count of successes across repeated independent trials (conversions across 1,000 ad impressions).
  • Poisson — the number of events in a fixed window, useful for rare, discrete events (server errors per hour, customer arrivals per minute).
  • Geometric — how many trials until the first success (attempts before a user finally converts).
  • Uniform — every value in a range is equally likely; used to initialize weights or draw random samples.
  • Exponential — models the waiting time between events (time until a customer churns, time between equipment failures).
  • Normal (Gaussian) — the classic bell curve. Measurement errors, natural human traits, and — critically — the noise term assumed in linear regression all follow this distribution.

Probability Distributions Models Are Built On

Each shape solves a different kind of uncertainty problem. Picking the right distribution to model your data (or your model's assumptions) directly affects whether a statistical method is even valid to use.

Likelihood and Maximum Likelihood Estimation

Likelihood flips the probability question around: instead of asking "given these parameters, how likely is this data," it asks "given this data, how likely are these parameters?" For data X = {x₁, ..., xₙ} and parameters θ:

L(θ | X) = ∏ P(xᵢ | θ)

Maximum Likelihood Estimation (MLE) 

It searches for the parameter values θ that make the observed data most probable. In practice, models maximize the log-likelihood instead — turning a product into a sum, which is far more numerically stable to optimize:

log L(θ | X) = Σ log P(xᵢ | θ)

This isn't an abstract technique — logistic regression, one of the most widely deployed classifiers in production systems, is trained by maximizing exactly this log-likelihood to find the weights that best separate two classes.

Entropy and Information Gain

Entropy measures how much uncertainty exists in a distribution:

H(X) = − Σ P(xᵢ) log P(xᵢ)	

A coin that's 50/50 has maximum entropy — you genuinely can't predict the outcome. A coin that lands heads 99% of the time has low entropy — you can guess correctly almost every time.

Entropy and Information Gain

Decision trees use exactly this calculation to decide where to split data. A split that produces low-entropy groups (mostly one class on each side) reduces uncertainty the most — that reduction is called information gain, and it's the criterion trees optimize at every node.

Confidence Intervals

A confidence interval expresses uncertainty around an estimate rather than reporting a single number as if it were exact. For a sample mean x̄ with standard deviation s and sample size n:

x̄ ± z · (s / √n)

If a model estimates a house is worth $410k ± $15k with 95% confidence, that range — not the single point estimate — is the honest statement of what the model actually knows.

Machine Learning Algorithms Built Directly on Probability

  • Naive Bayes Classifier — applies Bayes' theorem across every feature, assuming they're independent. Despite that simplifying (and often false) assumption, it remains a fast, effective baseline for text classification and spam filtering.
  • Hidden Markov Models (HMMs) — model systems with hidden states that produce observable outputs, used heavily in speech recognition and gene sequence analysis.
  • Bayesian Networks — graphical models that map out probabilistic dependencies between variables, used for causal reasoning and decision support in domains like medical diagnosis.
  • Gaussian Mixture Models (GMMs) — represent a dataset as a blend of several normal distributions, useful for clustering data that doesn't fall into one clean group, fitted using the Expectation-Maximization algorithm.

Once you can read a distribution, compute a conditional probability, and understand what entropy is measuring, most "How does this model actually decide?" questions in ML stop being mysterious — they're variations on the same handful of ideas above.