Probability Basics › Probability Distributions
Machine Learning from ScratchAll chapters Probability Basics › Probability DistributionsOne section · Sections in this chapter4 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
A probability distribution describes how probabilities are spread across the possible values of a random variable. It tells us which outcomes are likely and which are rare. Different types of random phenomena follow different patterns, and recognizing these patterns helps us model real-world processes effectively.
For discrete random variables, we use a probability mass function (PMF) that assigns probabilities to each possible value. The PMF must satisfy two conditions: all probabilities must be non-negative, and they must sum to one across all possible outcomes. For continuous random variables, we use a probability density function (PDF) that describes the relative likelihood of values in different regions. Unlike discrete probabilities, the PDF itself does not give probabilities directly. Instead, we integrate the PDF over an interval to find the probability that the variable falls within that range.
Example: PMF vs PDF - Understanding Discrete and Continuous Distributions
This visualization contrasts how probabilities are represented for discrete versus continuous random variables. The discrete case shows exact probabilities for specific outcomes (the height of each bar), while the continuous case shows a density curve where probabilities are areas under the curve.


Several probability distributions appear repeatedly due to their theoretical properties and empirical relevance. The normal distribution (Gaussian distribution) describes many natural phenomena and plays a central role in statistical theory due to the Central Limit Theorem. The binomial distribution models the number of successes in a fixed number of independent trials, such as counting how many emails out of 100 are spam. The Poisson distribution describes the number of events occurring in a fixed interval of time or space, useful for modeling rare events like server failures or customer arrivals. The exponential distribution models waiting times between events in a Poisson process, such as time between website visits.
Choosing the distribution that best describes your data helps you build an appropriate statistical model. Misspecifying the distribution can lead to incorrect inferences, poor predictions, and unreliable uncertainty estimates.
The discrete PMF example above is somewhat artificial. We defined specific probabilities for each outcome that conveniently sum to 1. In practice, PMFs are typically derived from theoretical distributions, like binomial or Poisson, that have mathematical formulas governing the probabilities. We use this simple example to build intuition before introducing these more complex distributions.
Example: Comparing Probability Distributions
The following visualization shows three fundamental probability distributions: the normal distribution describing continuous measurements, the binomial distribution describing count data from repeated trials, and the Poisson distribution describing rare event counts.



Calculating Probabilities from PMFs
Once we have defined a probability distribution, we can calculate the probability of specific outcomes or ranges of outcomes. The approach differs depending on whether we're working with discrete or continuous distributions.
For discrete distributions, we use the Probability Mass Function (PMF), which gives us , the probability that the random variable equals exactly a specific value. The PMF must satisfy two key properties:
- for all values (probabilities are non-negative)
- (probabilities sum to 1)
To find the probability of a range of outcomes, we simply sum the individual probabilities. For example, .
For continuous distributions, we use the Probability Density Function (PDF) along with integration to find probabilities over intervals. Unlike the PMF, the PDF does not give probabilities directly. Instead, we must integrate over an interval:
Here, denotes the probability density function (PDF) of the continuous random variable . But where does this function come from?
Each continuous distribution has its own specific PDF formula derived from the properties of that distribution. For example, the normal distribution has the familiar bell-curve formula .
When using statistical software like scipy.stats, these PDF formulas are built-in. Calling stats.norm.pdf(x) evaluates this formula for you. The key point is that while a PDF tells us the density of probability at each point, we must integrate it over an interval to get actual probabilities.
As we recall, integration is a mathematical operation that calculates the area under a curve. Imagine drawing the PDF curve on a graph and shading the region between the curve and the x-axis from point to point . The integral computes exactly this shaded area. In the context of probability, this area represents the probability that the random variable falls within that interval. Since the total area under the entire PDF curve equals 1 (representing 100% probability), the area under any portion of the curve tells us what fraction of the total probability lies in that range.
An important consequence is that for continuous distributions, for any specific value , where is any particular point in the continuous range of possible values. This may seem counterintuitive, but it makes sense when you consider that there are infinitely many possible values. What matters is the probability of falling within an interval, not at a specific point.
The Cumulative Distribution Function (CDF) provides another useful tool for calculating probabilities. The CDF, denoted , gives the probability that the random variable is less than or equal to :
For continuous distributions, the CDF is obtained by integrating the PDF from to :
In other words, the CDF at any point equals the total area under the PDF curve to the left of that point.
Example: Calculating Probabilities with the Binomial Distribution
Let's work through a concrete example to make these concepts clear. Imagine we're flipping a fair coin 10 times and want to calculate various probabilities. This scenario follows a binomial distribution with parameters (number of trials) and (probability of success/heads on each flip).
The binomial PMF gives us the exact probability of observing exactly heads in 10 flips:
Where is the binomial coefficient (number of ways to get exactly heads in 10 flips).
Let's understand where this formula comes from:
- : The probability of getting exactly heads, since each head has probability 0.5
- : The probability of getting exactly tails for the remaining flips
- : The number of different ways to arrange heads among 10 flips (since we don't care about the order, just the total count)
Multiplying these together gives us the total probability of observing exactly heads.
This formula is specific to the binomial distribution, which models the number of successes in a fixed number of independent trials (like coin flips). The general binomial PMF formula comes from probability theory literature and is given by , where is the number of trials, is the number of successes, and is the probability of success on each trial.
Let's calculate some specific probabilities and visualize the entire distribution:


Now let's use this distribution to calculate specific probabilities. Here are some common types of probability questions we might ask:
Exact probabilities (using PMF):
- = Probability of no heads (all tails)
- = Probability of exactly 5 heads
- = Probability of all heads
Cumulative probabilities (using CDF):
- = Probability of 3 or fewer heads
- = Probability of 7 or more heads
- = Probability of more than 5 heads
Range probabilities (using CDF subtraction):
- = Probability of 4 through 7 heads
- = Probability of 3 through 7 heads
Let's calculate these probabilities numerically:
Exact Probabilities (PMF): P(X = 0) = 0.000977 # No heads P(X = 5) = 0.246094 # Exactly 5 heads P(X = 10) = 0.000977 # All heads Cumulative Probabilities (CDF): P(X ≤ 3) = 0.171875 # At most 3 heads P(X ≥ 7) = 0.171875 # At least 7 heads P(X > 5) = 0.376953 # More than 5 heads Range Probabilities (CDF subtraction): P(3 ≤ X ≤ 7) = 0.890625 # 3 to 7 heads P(2 < X < 8) = 0.890625 # 3 to 7 heads
Notice how the probabilities behave:
- The most likely outcome is 5 heads (24.6% probability), which matches our intuition for a fair coin
- Extreme outcomes (0 or 10 heads) are very unlikely (0.1% each)
- The distribution is symmetric around the mean because p = 0.5
- Cumulative probabilities increase steadily as we move from left to right
- Range probabilities are calculated by subtracting CDF values: P(a ≤ X ≤ b) = F(b) - F(a-1)
This example demonstrates why probability calculations are so important: they allow us to quantify uncertainty and make informed decisions based on the likelihood of different outcomes.
scipy.stats Package for Probability CalculationsIn the calculations above, we used scipy.stats.binom.pmf() and scipy.stats.binom.cdf() to compute probabilities. These functions efficiently implement the formulas we discussed earlier.
If we were to calculate these from scratch:
- PMF (Probability Mass Function): We'd compute using
math.comb(n, k)for the binomial coefficient and standard arithmetic for the rest. - CDF (Cumulative Distribution Function): We'd sum up the PMF values: , which involves computing and adding each individual probability.
The scipy.stats package provides optimized implementations that handle numerical precision and edge cases, making it the preferred choice for practical work. However, understanding the underlying formulas is essential for building intuition about how these probabilities behave.