Probability for Data Science
Probability and Combinatorics
Probability: Core Ideas
Probability measures how likely an event is to occur. It is expressed as a number from 0 to 1:
A probability of 0 means the event cannot occur.
A probability of 1 means the event is certain to occur.
Values between 0 and 1 represent varying degrees of likelihood. A larger value indicates a more likely event.
Probabilities can also be written as percentages or fractions. For example, 0.2 is equivalent to 20% or 51.
Events and sample spaces
An event is a particular outcome or a collection of outcomes of interest. Examples include:
Getting heads when flipping a coin.
Rolling a 4 on a six-sided die.
Rolling a number divisible by 3.
Running a mile in under six minutes.
The sample space is the set of all possible outcomes of an experiment. For a coin flip, the sample space is {heads,tails}; for a standard six-sided die, it is {1,2,3,4,5,6}.
An outcome is favorable if it meets the condition specified by the event. Under the assumption that all outcomes are equally likely, theoretical probability is calculated as:
Basic examples
Coin flip: One of the two outcomes is heads, so
P(heads)=21=0.5Rolling a 4: There is one favorable outcome among six possible outcomes:
P(4)=61≈0.167Rolling a number divisible by 3: The favorable outcomes are 3 and 6, so
P(number divisible by 3)=62=31≈0.333
Probability allows events to be compared numerically. For instance, a lottery ticket may have a much smaller chance of winning than a coin toss has of landing heads.
Independent events
Two events are independent when the occurrence of one does not change the probability of the other. For independent events, the probability that both occur is the product of their individual probabilities:
For example, if drawing a card from a standard deck, the probability of drawing the ace of spades can be found by multiplying the probability of drawing an ace by the probability of drawing a spade, provided those events are treated as independent under the relevant sampling setup. Independence must be established; it does not apply automatically to every pair of events.
Experiments and Experimental Probability
An experiment is a process that produces recorded outcomes. A single performance of the process is a trial. For example, flipping a coin 20 times is one experiment containing 20 trials.
When the true probability is unknown or difficult to calculate, repeated trials can be used to estimate it. The probability estimated from observed results is an experimental probability:
This differs from theoretical probability, which is calculated from a model of the possible outcomes. Experimental and theoretical probabilities need not match exactly, especially when only a small number of trials have been conducted. With repeated observations, experimental results can provide a useful approximation.
For example, if a person waits in a queue on 8 out of 10 visits to a shop, the experimental probability of encountering a queue is:
This estimates the chance of a queue based on those observations; it does not guarantee that a queue will occur on the next visit.
Expected Value
Expected value describes the average outcome that a probability model predicts over many repetitions. It does not necessarily describe an outcome that can occur in a single trial.
Expected number of times an event occurs
For an event with probability P(A) repeated over n trials, the expected number of occurrences is:
For example, suppose a card is drawn, its suit is recorded, and the card is returned and the deck shuffled before the next draw. The probability of drawing a spade on any draw is 41. Over 20 draws, the expected number of spades is:
This means that 5 is the predicted average number of spades over many sets of 20 draws. It does not ensure that exactly 5 spades will appear in any particular set.
Expected value of numerical outcomes
When outcomes have numerical values, the expected value is the sum of each possible value multiplied by its probability:
For an archery target with three scoring regions:
10 points with probability 0.5
20 points with probability 0.4
100 points with probability 0.1
the expected score is:
A single shot cannot score 23 points. The value 23 is the long-run average score predicted by the model, not a possible score for one shot.
Expected values can support predictions and planning, but uncertainty remains. Forecasts, for example, often use ranges because the exact future outcome is unknown.
Probability Distributions and Two Dice
A probability distribution lists the probabilities associated with the possible values of a random outcome. It shows which outcomes are more or less likely.
Adding the results of two dice
When two standard six-sided dice are rolled, each die has 6 possible outcomes. The dice together therefore have:
equally likely ordered outcomes. When the values are added, different sums occur with different frequencies. For example, a sum of 7 can be obtained in 6 ways:
Thus:
The full frequency and probability distribution is:
Sum 2: Frequency 1; probability 361
Sum 3: Frequency 2; probability 362
Sum 4: Frequency 3; probability 363
Sum 5: Frequency 4; probability 364
Sum 6: Frequency 5; probability 365
Sum 7: Frequency 6; probability 366
Sum 8: Frequency 5; probability 365
Sum 9: Frequency 4; probability 364
Sum 10: Frequency 3; probability 363
Sum 11: Frequency 2; probability 362
Sum 12: Frequency 1; probability 361
A frequency is the number of times an outcome appears in the sample space. Dividing each frequency by the total number of outcomes gives the probability of that outcome. The resulting collection is a probability frequency distribution.
The sum 7 has the highest probability, but it still occurs only 61 of the time. Being the most likely individual outcome does not make an outcome certain—or even more likely than not.
Expected sum of two dice
The expected value of the sum is 7. This can be obtained from the distribution by multiplying each possible sum by its probability and adding the results:
It is also possible to calculate this by adding the expected values of the two dice. Each die has expected value 3.5, so the expected sum is 3.5+3.5=7.
The expected value is at the center of the symmetric distribution, where the more probable sums cluster. It is useful for describing long-run averages, but it does not mean that every pair of dice will sum to 7.
Complements and Probability Sums
The complement of an event consists of every outcome in the sample space that is not in that event. If event A is rolling an even number on a standard die, its complement is rolling an odd number.
The complement of A is commonly written as Ac or A′. Taking the complement twice returns the original event:
Probabilities of complements
An event and its complement together account for the entire sample space. Their probabilities therefore sum to 1:
So the probability of a complement can be found by subtraction:
For a standard die, the complement of rolling a 3 is not rolling a 3. Since P(3)=61:
This is equivalent to counting the five favorable outcomes directly: 1, 2, 4, 5, and 6.
Complements are especially useful when an event includes many outcomes but its opposite is simple to describe. For example, calculating the probability of “not rolling a 3” can be easier than listing all five other die outcomes.
When probabilities sum to 1
The probabilities of all mutually exclusive outcomes that together cover the full sample space sum to 1. For a coin, heads and tails are mutually exclusive and exhaustive, so:
A sum below 1 indicates that some possible outcomes have not been included, if the outcomes are intended to cover the whole sample space. A sum above 1 can result from adding probabilities of events that overlap, thereby counting some outcomes more than once. Probabilities cannot represent a certainty greater than 1.
Combinatorics: Counting Possible Outcomes
Combinatorics is the study of counting selections and arrangements from a finite set. It helps determine how many favorable outcomes or total outcomes are possible, often before a probability is calculated.
The key questions are:
Does the order of selected elements matter?
Can an element be selected more than once?
Must every element in the set be used?
The answers determine whether the appropriate method is a permutation, variation, or combination.
Factorials
For a positive integer n, the factorial n! is the product of all positive integers from 1 through n:
For example:
By definition, 0!=1. In elementary counting, factorials are defined for nonnegative integers; negative integers do not have factorials under this definition.
A useful recursive relationship is:
For instance, 6!=6⋅5!. Factorial ratios can often be simplified by canceling shared factors. For example:
This cancellation is useful when applying counting formulas, because it avoids calculating large factorials in full.
Permutations: Arranging Every Element
A permutation is an arrangement of elements in which order matters. When all n distinct elements are arranged, the number of permutations is:
For three distinct drivers occupying first, second, and third place, there are:
The first position has 3 choices, the second has 2 remaining choices, and the final position has 1 choice.
In general, the number of options decreases as positions are filled. For n distinct elements, the number of arrangements is:
Permutations are appropriate when the entire set is arranged and different orders count as different outcomes.
Variations: Selecting and Arranging Some Elements
A variation selects a specified number of elements and arranges them, so order matters. Variations can be calculated with or without repetition.
Variations with repetition
If there are n choices for each of p ordered positions, and choices can be repeated, then:
For a two-letter code using the letters A, B, and C, each position has 3 choices. Repetition is allowed, so:
The codes include AA, AB, AC, BA, BB, BC, CA, CB, and CC. With all 26 letters available, there are:
possible two-letter codes.
Variations without repetition
If the p selected elements must be distinct, the number of ordered arrangements is:
This is also the product:
For example, a relay team has 5 people and must assign 4 distinct running positions. The number of possible ordered teams is:
The first position has 5 choices, the second has 4, the third has 3, and the fourth has 2. A runner cannot occupy more than one position.
Combinations: Selecting Without Arranging
A combination is a selection in which order does not matter. Choosing Alex, Sarah, and Dave is the same group regardless of the order in which they are named.
Combinations without repetition
The number of ways to choose p distinct elements from n elements, without repetition, is:
For example, choosing 3 people from a group of 10 gives:
The corresponding number of ordered selections is:
Each group of 3 people can be arranged in 3!=6 orders. Therefore, the number of combinations is the number of variations divided by the number of ways to arrange each selected group:
Combinations are appropriate when only the membership of the selected group matters, not the order of selection.
Symmetry of combinations
Choosing p elements from a set of n is equivalent to choosing the n−p elements to leave out:
For example, choosing 4 fruits from 6 is equivalent to choosing the 2 fruits to leave behind:
Similarly, choosing 7 employees from 10 is equivalent to choosing 3 employees not to send:
This symmetry can simplify calculations: when p is greater than half of n, it is often easier to calculate using n−p.
Combinations with repetition
When order does not matter and elements may be selected more than once, the number of combinations is:
For example, selecting 2 desserts from 7 types, with the possibility of choosing the same type twice, gives:
A selection of chocolate and vanilla is counted once, regardless of who receives each dessert. If the recipients mattered, the selection would be ordered and a variation method would be more appropriate.
Choosing the Correct Counting Method
Permutations
Order matters: Yes.
How many elements are used: All elements in the set.
Repetition: Not part of the standard permutation formula for arranging distinct elements.
Example: Arranging four chosen relay runners in four positions.
Variations
Order matters: Yes.
How many elements are used: A selected number of elements from the set.
Repetition: May be allowed or disallowed.
Example: Choosing four runners from six and assigning their running positions.
Combinations
Order matters: No.
How many elements are used: A selected number of elements from the set.
Repetition: May be allowed or disallowed.
Example: Choosing four runners from six when only team membership matters.
For selections without repetition, the key relationship is:
The variations count each ordering separately, while combinations group all orderings of the same selected elements together.
Counting Choices from Separate Categories
When a choice consists of independent components from separate categories, the multiplication principle applies: multiply the number of options for each component.
For a diner menu with 3 sandwiches, 2 sides, and 2 drinks, the total number of menus is:
For an advertisement with 3 headings, 5 thumbnails, 3 descriptions, and 2 buttons, the total number of versions is:
This principle applies when every option in one category can be paired with every option in the other categories. It is useful for estimating the number of possibilities in design, marketing, planning, and other practical settings.
Applying Counting to a Lottery
Suppose a lottery ticket must select 5 numbers from 69, without repetition and without regard to order, and also select one “Powerball” number from 26 possibilities.
Selecting the five main numbers
Since order does not matter and numbers cannot repeat, the main numbers are chosen using combinations:
Selecting the Powerball number
There are 26 possible Powerball numbers, so the probability of selecting the correct one with a single choice is:
Counting all possible tickets and finding the probability
Each selection of five main numbers can be paired with each Powerball number. The total number of possible tickets is therefore:
With one ticket, the probability of matching the full combination is:
If k distinct tickets are purchased, the probability of winning is 292,201,338k, assuming the tickets represent different combinations and the draw is equally likely to produce any combination.
Worked Application: Comparing Meal Deals
Suppose a menu offers 26 pizzas, 4 drinks, and 7 desserts. The number of possible orders depends not just on how many items are offered, but on whether order matters and whether repetition is allowed.
One-person deal
A one-person deal contains one pizza, one drink, and one dessert. Each category is chosen independently, so the multiplication principle gives:
There are 728 possible orders.
Family deal
A family deal contains two pizzas, one small drink, one large drink, and two desserts.
Two pizzas: Assume the two pizzas must be different, and the order in which they are listed does not matter. This is a combination without repetition:
The two drinks: The small and large drink occupy different roles, and either role can use any of the 4 drink options. Repetition is allowed, so:
Two desserts: The dessert types can repeat, and the order does not matter because the order does not assign a dessert to a particular person. This is a combination with repetition:
Multiplying the choices for the three parts gives:
There are 145,600 possible family-deal orders under these assumptions.
Double Delight
The Double Delight contains two different pizzas, two large drinks, and two desserts.
Pizzas: The two different pizzas are unordered, giving:
Drinks: The drinks must be different, and order matters because the drinks are assigned to particular recipients. This is a variation without repetition:
Desserts: Repetition is allowed, and order does not matter, giving:
The total number of possible Double Delight orders is:
The two larger deals offer far more possibilities than the one-person deal. Under these assumptions, the Family Deal has 145,600 possible orders, which is 36,400 more than the Double Delight’s 109,200. The difference arises because the drink choices are counted differently: the Family Deal allows 16 ordered drink pairs, while the Double Delight has 12 ordered pairs of distinct drinks.
Key Takeaways
Probability quantifies how likely an event is, using values from 0 to 1.
Theoretical probability compares favorable outcomes with all possible outcomes; experimental probability estimates likelihood from observed trials.
Expected value describes a long-run average and need not be a possible result of one trial.
A probability distribution assigns probabilities to all possible values of an outcome; frequencies can be converted to probabilities by dividing by the size of the sample space.
An event and its complement have probabilities that sum to 1.
Permutations arrange all elements, variations select and arrange some elements, and combinations select elements without regard to order.
Repetition and order must be considered explicitly when choosing a counting formula.
When a task combines choices from separate categories, the total number of possibilities is found by multiplying the number of options in each category.

Ask anything
We've read this whole study set, so questions about it get the best answers.