1. Home
  2. Explore
  3. Statistics
  4. Probability for Data Science

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

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 000 to 111:

  • A probability of 000 means the event cannot occur.

  • A probability of 111 means the event is certain to occur.

  • Values between 000 and 111 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.20.20.2 is equivalent to 20%20\%20% or 15\frac{1}{5}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 444 on a six-sided die.

  • Rolling a number divisible by 333.

  • 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}\{\text{heads}, \text{tails}\}{heads,tails}; for a standard six-sided die, it is {1,2,3,4,5,6}\{1,2,3,4,5,6\}{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:

P(A)=number of favorable outcomesnumber of possible outcomesP(A)=\frac{\text{number of favorable outcomes}}{\text{number of possible outcomes}}P(A)=number of possible outcomesnumber of favorable outcomes​

Basic examples

  • Coin flip: One of the two outcomes is heads, so

    P(heads)=12=0.5P(\text{heads})=\frac{1}{2}=0.5P(heads)=21​=0.5
  • Rolling a 444: There is one favorable outcome among six possible outcomes:

    P(4)=16≈0.167P(4)=\frac{1}{6}\approx 0.167P(4)=61​≈0.167
  • Rolling a number divisible by 333: The favorable outcomes are 333 and 666, so

    P(number divisible by 3)=26=13≈0.333P(\text{number divisible by }3)=\frac{2}{6}=\frac{1}{3}\approx 0.333P(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:

P(A and B)=P(A)P(B)P(A\text{ and }B)=P(A)P(B)P(A and B)=P(A)P(B)

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 202020 times is one experiment containing 202020 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:

Experimental probability=number of successful trialstotal number of trials\text{Experimental probability} = \frac{\text{number of successful trials}}{\text{total number of trials}}Experimental probability=total number of trialsnumber of successful trials​

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 888 out of 101010 visits to a shop, the experimental probability of encountering a queue is:

810=0.8\frac{8}{10}=0.8108​=0.8

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)P(A)P(A) repeated over nnn trials, the expected number of occurrences is:

E[number of occurrences of A]=nP(A)E[\text{number of occurrences of }A]=nP(A)E[number of occurrences of A]=nP(A)

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 14\frac{1}{4}41​. Over 202020 draws, the expected number of spades is:

20(14)=520\left(\frac{1}{4}\right)=520(41​)=5

This means that 555 is the predicted average number of spades over many sets of 202020 draws. It does not ensure that exactly 555 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:

E[X]=∑xxP(X=x)E[X]=\sum_x xP(X=x)E[X]=∑x​xP(X=x)

For an archery target with three scoring regions:

  • 101010 points with probability 0.50.50.5

  • 202020 points with probability 0.40.40.4

  • 100100100 points with probability 0.10.10.1

the expected score is:

E[X]=(10)(0.5)+(20)(0.4)+(100)(0.1)=23E[X]=(10)(0.5)+(20)(0.4)+(100)(0.1)=23E[X]=(10)(0.5)+(20)(0.4)+(100)(0.1)=23

A single shot cannot score 232323 points. The value 232323 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 666 possible outcomes. The dice together therefore have:

6×6=366\times 6=366×6=36

equally likely ordered outcomes. When the values are added, different sums occur with different frequencies. For example, a sum of 777 can be obtained in 666 ways:

(1,6),(2,5),(3,4),(4,3),(5,2),(6,1)(1,6), (2,5), (3,4), (4,3), (5,2), (6,1)(1,6),(2,5),(3,4),(4,3),(5,2),(6,1)

Thus:

P(sum=7)=636=16P(\text{sum}=7)=\frac{6}{36}=\frac{1}{6}P(sum=7)=366​=61​

The full frequency and probability distribution is:

  • Sum 222: Frequency 111; probability 136\frac{1}{36}361​

  • Sum 333: Frequency 222; probability 236\frac{2}{36}362​

  • Sum 444: Frequency 333; probability 336\frac{3}{36}363​

  • Sum 555: Frequency 444; probability 436\frac{4}{36}364​

  • Sum 666: Frequency 555; probability 536\frac{5}{36}365​

  • Sum 777: Frequency 666; probability 636\frac{6}{36}366​

  • Sum 888: Frequency 555; probability 536\frac{5}{36}365​

  • Sum 999: Frequency 444; probability 436\frac{4}{36}364​

  • Sum 101010: Frequency 333; probability 336\frac{3}{36}363​

  • Sum 111111: Frequency 222; probability 236\frac{2}{36}362​

  • Sum 121212: Frequency 111; probability 136\frac{1}{36}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 777 has the highest probability, but it still occurs only 16\frac{1}{6}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 777. This can be obtained from the distribution by multiplying each possible sum by its probability and adding the results:

E[X]=∑s=212sP(X=s)=7E[X]=\sum_{s=2}^{12}sP(X=s)=7E[X]=∑s=212​sP(X=s)=7

It is also possible to calculate this by adding the expected values of the two dice. Each die has expected value 3.53.53.5, so the expected sum is 3.5+3.5=73.5+3.5=73.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 777.


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 AAA is rolling an even number on a standard die, its complement is rolling an odd number.

The complement of AAA is commonly written as AcA^cAc or A′A'A′. Taking the complement twice returns the original event:

(Ac)c=A(A^c)^c=A(Ac)c=A

Probabilities of complements

An event and its complement together account for the entire sample space. Their probabilities therefore sum to 111:

P(A)+P(Ac)=1P(A)+P(A^c)=1P(A)+P(Ac)=1

So the probability of a complement can be found by subtraction:

P(Ac)=1−P(A)P(A^c)=1-P(A)P(Ac)=1−P(A)

For a standard die, the complement of rolling a 333 is not rolling a 333. Since P(3)=16P(3)=\frac{1}{6}P(3)=61​:

P(not 3)=1−16=56P(\text{not }3)=1-\frac{1}{6}=\frac{5}{6}P(not 3)=1−61​=65​

This is equivalent to counting the five favorable outcomes directly: 111, 222, 444, 555, and 666.

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 333” can be easier than listing all five other die outcomes.

When probabilities sum to 111

The probabilities of all mutually exclusive outcomes that together cover the full sample space sum to 111. For a coin, heads and tails are mutually exclusive and exhaustive, so:

P(heads)+P(tails)=1P(\text{heads})+P(\text{tails})=1P(heads)+P(tails)=1

A sum below 111 indicates that some possible outcomes have not been included, if the outcomes are intended to cover the whole sample space. A sum above 111 can result from adding probabilities of events that overlap, thereby counting some outcomes more than once. Probabilities cannot represent a certainty greater than 111.


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 nnn, the factorial n!n!n! is the product of all positive integers from 111 through nnn:

n!=1⋅2⋅3⋯nn!=1\cdot 2\cdot 3\cdots nn!=1⋅2⋅3⋯n

For example:

3!=1⋅2⋅3=63!=1\cdot 2\cdot 3=63!=1⋅2⋅3=6

By definition, 0!=10!=10!=1. In elementary counting, factorials are defined for nonnegative integers; negative integers do not have factorials under this definition.

A useful recursive relationship is:

n!=n(n−1)!n!=n(n-1)!n!=n(n−1)!

For instance, 6!=6⋅5!6!=6\cdot 5!6!=6⋅5!. Factorial ratios can often be simplified by canceling shared factors. For example:

7!4!=1⋅2⋅3⋅4⋅5⋅6⋅71⋅2⋅3⋅4=5⋅6⋅7\frac{7!}{4!} = \frac{1\cdot2\cdot3\cdot4\cdot5\cdot6\cdot7} {1\cdot2\cdot3\cdot4} =5\cdot6\cdot74!7!​=1⋅2⋅3⋅41⋅2⋅3⋅4⋅5⋅6⋅7​=5⋅6⋅7

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 nnn distinct elements are arranged, the number of permutations is:

P(n)=n!P(n)=n!P(n)=n!

For three distinct drivers occupying first, second, and third place, there are:

3!=3⋅2⋅1=63!=3\cdot2\cdot1=63!=3⋅2⋅1=6

The first position has 333 choices, the second has 222 remaining choices, and the final position has 111 choice.

In general, the number of options decreases as positions are filled. For nnn distinct elements, the number of arrangements is:

n(n−1)(n−2)⋯1=n!n(n-1)(n-2)\cdots 1=n!n(n−1)(n−2)⋯1=n!

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 nnn choices for each of ppp ordered positions, and choices can be repeated, then:

Vrep(n,p)=npV_{\text{rep}}(n,p)=n^pVrep​(n,p)=np

For a two-letter code using the letters A, B, and C, each position has 333 choices. Repetition is allowed, so:

Vrep(3,2)=32=9V_{\text{rep}}(3,2)=3^2=9Vrep​(3,2)=32=9

The codes include AA, AB, AC, BA, BB, BC, CA, CB, and CC. With all 262626 letters available, there are:

262=67626^2=676262=676

possible two-letter codes.

Variations without repetition

If the ppp selected elements must be distinct, the number of ordered arrangements is:

V(n,p)=n!(n−p)!V(n,p)=\frac{n!}{(n-p)!}V(n,p)=(n−p)!n!​

This is also the product:

n(n−1)(n−2)⋯(n−p+1)n(n-1)(n-2)\cdots(n-p+1)n(n−1)(n−2)⋯(n−p+1)

For example, a relay team has 555 people and must assign 444 distinct running positions. The number of possible ordered teams is:

V(5,4)=5!(5−4)!=5!1!=5⋅4⋅3⋅2=120V(5,4)=\frac{5!}{(5-4)!} =\frac{5!}{1!} =5\cdot4\cdot3\cdot2 =120V(5,4)=(5−4)!5!​=1!5!​=5⋅4⋅3⋅2=120

The first position has 555 choices, the second has 444, the third has 333, and the fourth has 222. 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 ppp distinct elements from nnn elements, without repetition, is:

C(n,p)=(np)=n!p!(n−p)!C(n,p)=\binom{n}{p}=\frac{n!}{p!(n-p)!}C(n,p)=(pn​)=p!(n−p)!n!​

For example, choosing 333 people from a group of 101010 gives:

C(10,3)=10!3!7!=120C(10,3)=\frac{10!}{3!7!}=120C(10,3)=3!7!10!​=120

The corresponding number of ordered selections is:

V(10,3)=10⋅9⋅8=720V(10,3)=10\cdot9\cdot8=720V(10,3)=10⋅9⋅8=720

Each group of 333 people can be arranged in 3!=63!=63!=6 orders. Therefore, the number of combinations is the number of variations divided by the number of ways to arrange each selected group:

C(n,p)=V(n,p)p!C(n,p)=\frac{V(n,p)}{p!}C(n,p)=p!V(n,p)​

Combinations are appropriate when only the membership of the selected group matters, not the order of selection.

Symmetry of combinations

Choosing ppp elements from a set of nnn is equivalent to choosing the n−pn-pn−p elements to leave out:

(np)=(nn−p)\binom{n}{p}=\binom{n}{n-p}(pn​)=(n−pn​)

For example, choosing 444 fruits from 666 is equivalent to choosing the 222 fruits to leave behind:

(64)=(62)=15\binom{6}{4}=\binom{6}{2}=15(46​)=(26​)=15

Similarly, choosing 777 employees from 101010 is equivalent to choosing 333 employees not to send:

(107)=(103)=120\binom{10}{7}=\binom{10}{3}=120(710​)=(310​)=120

This symmetry can simplify calculations: when ppp is greater than half of nnn, it is often easier to calculate using n−pn-pn−p.

Combinations with repetition

When order does not matter and elements may be selected more than once, the number of combinations is:

Crep(n,p)=(n+p−1p)=(n+p−1)!p!(n−1)!C_{\text{rep}}(n,p)=\binom{n+p-1}{p} =\frac{(n+p-1)!}{p!(n-1)!}Crep​(n,p)=(pn+p−1​)=p!(n−1)!(n+p−1)!​

For example, selecting 222 desserts from 777 types, with the possibility of choosing the same type twice, gives:

Crep(7,2)=(82)=28C_{\text{rep}}(7,2)=\binom{8}{2}=28Crep​(7,2)=(28​)=28

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:

combinations=variationspermutations of the selected elements\text{combinations} = \frac{\text{variations}}{\text{permutations of the selected elements}}combinations=permutations of the selected elementsvariations​

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 333 sandwiches, 222 sides, and 222 drinks, the total number of menus is:

3⋅2⋅2=123\cdot2\cdot2=123⋅2⋅2=12

For an advertisement with 333 headings, 555 thumbnails, 333 descriptions, and 222 buttons, the total number of versions is:

3⋅5⋅3⋅2=903\cdot5\cdot3\cdot2=903⋅5⋅3⋅2=90

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 555 numbers from 696969, without repetition and without regard to order, and also select one “Powerball” number from 262626 possibilities.

Selecting the five main numbers

Since order does not matter and numbers cannot repeat, the main numbers are chosen using combinations:

(695)=69!5!64!=11,238,513\binom{69}{5} = \frac{69!}{5!64!} = 11{,}238{,}513(569​)=5!64!69!​=11,238,513

Selecting the Powerball number

There are 262626 possible Powerball numbers, so the probability of selecting the correct one with a single choice is:

126\frac{1}{26}261​

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:

(695)⋅26=11,238,513⋅26=292,201,338\binom{69}{5}\cdot26 = 11{,}238{,}513\cdot26 = 292{,}201{,}338(569​)⋅26=11,238,513⋅26=292,201,338

With one ticket, the probability of matching the full combination is:

1292,201,338\frac{1}{292{,}201{,}338}292,201,3381​

If kkk distinct tickets are purchased, the probability of winning is k292,201,338\frac{k}{292{,}201{,}338}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 262626 pizzas, 444 drinks, and 777 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:

26⋅4⋅7=72826\cdot4\cdot7=72826⋅4⋅7=728

There are 728728728 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:

(262)=325\binom{26}{2}=325(226​)=325

The two drinks: The small and large drink occupy different roles, and either role can use any of the 444 drink options. Repetition is allowed, so:

42=164^2=1642=16

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:

(7+2−12)=(82)=28\binom{7+2-1}{2}=\binom{8}{2}=28(27+2−1​)=(28​)=28

Multiplying the choices for the three parts gives:

325⋅16⋅28=145,600325\cdot16\cdot28=145{,}600325⋅16⋅28=145,600

There are 145,600145{,}600145,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:

(262)=325\binom{26}{2}=325(226​)=325

Drinks: The drinks must be different, and order matters because the drinks are assigned to particular recipients. This is a variation without repetition:

V(4,2)=4!(4−2)!=4⋅3=12V(4,2)=\frac{4!}{(4-2)!}=4\cdot3=12V(4,2)=(4−2)!4!​=4⋅3=12

Desserts: Repetition is allowed, and order does not matter, giving:

(82)=28\binom{8}{2}=28(28​)=28

The total number of possible Double Delight orders is:

325⋅12⋅28=109,200325\cdot12\cdot28=109{,}200325⋅12⋅28=109,200

The two larger deals offer far more possibilities than the one-person deal. Under these assumptions, the Family Deal has 145,600145{,}600145,600 possible orders, which is 36,40036{,}40036,400 more than the Double Delight’s 109,200109{,}200109,200. The difference arises because the drink choices are counted differently: the Family Deal allows 161616 ordered drink pairs, while the Double Delight has 121212 ordered pairs of distinct drinks.


Key Takeaways

  • Probability quantifies how likely an event is, using values from 000 to 111.

  • 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 111.

  • 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.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent