Recommended resources
The freely available resources this lesson will direct you to.
- Basic Probability Distributions Explained: Bernoulli, Binomial, Categorical, Multinomialwww.youtube.com
- Stanford CS229: Machine Learning | Summer 2019 | Lecture 3 - Probability and Statisticswww.youtube.com
- CHAPTER 2 Estimating Probabilitieswww.cs.cmu.edu
- Probability Theory Review for Machine Learningsee.stanford.edu
Welcome to the start of your journey into the theoretical foundations of machine learning. Given your extensive background in computer science, you're well-equipped to appreciate the rigorous, formal-yet-practical nature of this field. This first module establishes the mathematical bedrock upon which all machine learning is built.
Our first topic is probability distributions. In machine learning, we are almost always dealing with uncertainty—uncertainty in our data, in our model's predictions, and in the parameters of the model itself. Probability distributions provide the mathematical language to quantify and manipulate this uncertainty. In this lesson, we will describe three of the most important distributions—Bernoulli, Categorical, and Gaussian—and explore their fundamental roles in framing and solving machine learning problems. This will lay the groundwork for our next topic: using data to update our beliefs, a core concept in learning.
From Randomness to Real Numbers
At its heart, machine learning is about building models from data. Since data is generated by real-world processes that are inherently random or too complex to model deterministically, we turn to probability.
A random variable, typically denoted by a capital letter like , is a variable whose value is a numerical outcome of a random phenomenon. It provides a crucial bridge from abstract outcomes (like "heads" or "tails") to the real number line, where we can perform mathematical operations.
To begin, let's watch a segment from a Stanford lecture that reviews these foundational concepts.
Stanford CS229: Machine Learning | Summer 2019 | Lecture 3 - Probability and Statistics
This video provides a clear review of fundamental probability concepts.
Watch the section from random variables to the end of the discussion on discrete vs. continuous variables. Pay close attention to the distinction between a Probability Mass Function (PMF), used for discrete variables that take on a finite set of values, and a Probability Density Function (PDF), used for continuous variables that can take any value within a given range.
As the video explains, for a discrete random variable, the PMF, , gives the probability that the variable takes on a specific value . The sum of all probabilities across all possible values is 1.
For a continuous random variable, the PDF, , is a function where the area under the curve between two points and gives the probability . A key and sometimes counter-intuitive point is that for any continuous random variable, the probability of it taking on any single specific value is zero. Probability is only non-zero over an interval.

Distributions for Classification: Bernoulli and Categorical
Many machine learning problems are classification tasks, where the goal is to assign a label to an input. The Bernoulli and Categorical distributions are the natural starting points for modeling these labels.
The Bernoulli Distribution: Two Possible Outcomes
The simplest case is binary classification, where there are only two possible outcomes.
- Is an email spam or not spam?
- Will a customer click on an ad or not?
- Is a credit card transaction fraudulent or legitimate?
The Bernoulli distribution models a single trial with two outcomes, typically labeled 0 (failure) and 1 (success). It is defined by a single parameter, , which is the probability of the outcome being 1.
The video below provides a concise explanation.
Basic Probability Distributions Explained: Bernoulli, Binomial, Categorical, Multinomial
This video introduces the Bernoulli distribution with a simple coin-flip analogy.
Please watch the section on the Bernoulli distribution.
As the video shows, the PMF can be written elegantly as:
If the outcome is 1 (success), the term becomes 1, leaving . If the outcome is 0 (failure), the term becomes 1, leaving .
In machine learning, we don't just model a single event. We build models that predict the parameter based on some input features. For example, in logistic regression, the model takes the features of an email (words, sender, etc.) and computes a probability that the email is spam ().
The Categorical Distribution: Multiple Possible Outcomes
When a classification task involves more than two outcomes, we generalize from the Bernoulli to the Categorical distribution.
- Classifying a handwritten digit (0, 1, ..., 9).
- Identifying the species of a flower from a photograph.
- Tagging a news article with a topic (e.g., 'Sports', 'Politics', 'Technology').
The Categorical distribution models a single trial with possible outcomes. It is parameterized by a vector of probabilities , where is the probability of the -th outcome, and .
Basic Probability Distributions Explained: Bernoulli, Binomial, Categorical, Multinomial
This video continues by explaining the Categorical distribution as a generalization of the Bernoulli.
Now, watch the section covering the Categorical distribution.
In an ML context, a multi-class classification model (like a neural network with a softmax output layer) takes an input (e.g., an image) and outputs the parameter vector , representing the probability for each of the classes.
To deepen your theoretical understanding, the following reading from Tom Mitchell's book formally introduces these distributions and, importantly, connects them to the fundamental ML concept of parameter estimation.
CHAPTER 2 Estimating Probabilities
This chapter provides a formal treatment of how we estimate the parameters of distributions like Bernoulli and Categorical from data, a process that is at the heart of "learning."
First, read the section that formally defines the Bernoulli random variable and distribution. Next, skip to the section "Working with Other Probability Distributions" and read about the Categorical distribution as a generalization for variables with many values. Note how the formula for estimating its parameters is a direct extension of the binary case.
The Gaussian Distribution: Modeling Continuous Data
While discrete distributions are perfect for labels, much of the data we encounter in the real world is continuous: sensor readings, financial data, physical measurements, etc. The most important distribution for modeling such data is the Gaussian distribution, also known as the Normal distribution or "bell curve."
It is defined by two parameters:
- The mean (), which represents the center or expected value of the distribution.
- The variance (), which measures the spread or dispersion of the data around the mean. The square root of the variance, , is the standard deviation.
The PDF of the Gaussian distribution is:
Let's consult the Stanford course notes for a formal description.
Probability Theory Review for Machine Learning
This document provides the mathematical definition of the Gaussian distribution and its parameters.
In section 4, "Some Important Distributions," find the subsection on the Gaussian distribution. Pay attention to the formula and the description of its parameters, \mu and \sigma^2.
The Gaussian distribution is ubiquitous in machine learning for several reasons:
- Modeling Features: It's often a reasonable assumption for the distribution of real-valued input features, such as the height of a person or the price of a stock.
- Modeling Noise: In regression problems, we often assume that the errors (the difference between our model's predictions and the true values) are Gaussian-distributed. This assumption is the foundation for models like linear regression.
- Central Limit Theorem: This powerful theorem states that the sum of many independent random variables tends toward a Gaussian distribution, regardless of the original distributions. This provides a theoretical justification for its widespread appearance.
- Mathematical Convenience: The Gaussian has mathematical properties that make it easy to work with in many derivations.

The Multivariate Gaussian Distribution
In practice, our data rarely consists of a single feature. We usually work with data points that are vectors in a high-dimensional space (e.g., an image is a vector of pixel values). The Multivariate Gaussian distribution is the generalization of the Gaussian to multiple dimensions.
Instead of a scalar mean and variance , it is parameterized by:
- A mean vector , which defines the center of the distribution in -dimensional space.
- A covariance matrix , an matrix that describes not only the variance of each dimension along its diagonal but also how the dimensions vary with respect to each other (the covariance) in its off-diagonal elements.
The Stanford lecture video provides excellent visual intuition for how and shape the distribution.
Stanford CS229: Machine Learning | Summer 2019 | Lecture 3 - Probability and Statistics
This segment offers a detailed walkthrough of the multivariate Gaussian, connecting its formula to concepts from linear algebra and providing powerful visualizations.
Watch the segment from the beginning of the multivariate Gaussian discussion until the end of the visualizations. As you watch, consider how your knowledge of linear algebra (determinants, matrix inverses, quadratic forms) helps in deciphering the PDF formula. Focus on how changes in the covariance matrix \boldsymbol{\Sigma} affect the shape and orientation of the probability density.
Conclusion
In this introductory lesson, we have established the first pillar of our theoretical foundation. We explored how random variables and probability distributions are used to formally describe data-generating processes.
Here are the key takeaways:
- Probability distributions are the language of uncertainty in machine learning. We distinguish between discrete variables (modeled by PMFs) and continuous variables (modeled by PDFs).
- The Bernoulli distribution models a single trial with two outcomes and is the foundation for binary classification. It is parameterized by , the probability of success.
- The Categorical distribution generalizes the Bernoulli to a single trial with outcomes, making it the basis for multi-class classification. It is parameterized by a vector of probabilities.
- The Gaussian distribution is the most common model for continuous data, defined by its mean and variance . Its multivariate version is critical for modeling high-dimensional data vectors, using a mean vector and a covariance matrix .
In our next lesson, we will build directly on these concepts. Now that we can postulate a probabilistic model for our data, we will ask: how can we use observed data to infer the parameters of our model? This will lead us to one of the most fundamental rules in all of statistics and machine learning: Bayes' theorem.