1.5. Events

Last updated: May 26th, 20202020-05-26Project preview
In [1]:
import pandas as pd

Events

Again on our small dataset, let's think of the experiment of picking a person and printing their age:

In [2]:
dataset =  pd.DataFrame({
    'Person #':[1,2,3,4,5,6,7,8,9,10],
    'City':['SF','SF','NY','NY','NY','SF','NY','SF','SF','SF'],
    'Age':[41,26,28,53,32,51,65,49,25,33]
})
dataset
Out[2]:
Person # City Age
0 1 SF 41
1 2 SF 26
2 3 NY 28
3 4 NY 53
4 5 NY 32
5 6 SF 51
6 7 NY 65
7 8 SF 49
8 9 SF 25
9 10 SF 33
In [3]:
dataset.sample(1)['Age'].values[0]
Out[3]:
53

Remember that for this experiment our sample space was $\Omega = \{25,26,28,32,33,41,49,51,53,65\}$.

But we can also think of the sample space as every integer from $25$ to $65$, just thinking that the probability of those numbers that do not appear in the dataset is $0$, so $\Omega = \{25,...,65\}$.

Now we are going to think about situations that we are interested in. For example, imagine we are interested in the case where the person we pick is younger than $35$. What are our options?

The outcomes we are thinking about are: $E=\{25,26,27,28,29,30,31,32,33,34\}$. We can notice this set of outcomes is a subset of $\Omega$.

We will call event to every subset of $\Omega$.

In further videos we are going to learn how to calculate probabilities of events, but for now let's look at how we can express combinations of events with set operations.

For that, let's first explore the commands for set operations in Python, using our set $E$ and a set $F$ of the ages that are prime numbers:

In [5]:
E = {25,26,27,28,29,30,31,32,33,34}
F = {29,31,37,41,43,47,53,59,61}

print(E.union(F))
print(E|F)

print(E.intersection(F))
print(E&F)

print(E.difference(F))
print(E-F)

print(E.symmetric_difference(F))
print(E^F)
{25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 37, 41, 43, 47, 53, 59, 61}
{25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 37, 41, 43, 47, 53, 59, 61}
{29, 31}
{29, 31}
{32, 33, 34, 25, 26, 27, 28, 30}
{32, 33, 34, 25, 26, 27, 28, 30}
{32, 33, 34, 37, 27, 41, 43, 47, 61, 53, 25, 26, 59, 28, 30}
{32, 33, 34, 37, 27, 41, 43, 47, 61, 53, 25, 26, 59, 28, 30}

With these operations we can represent the following more complex events:

  • $E\cup F=$ "The person we pick is younger than $35$ or their age is a prime number".
  • $E\cap F=$ "The person we pick is younger than $35$ and their age is a prime number".
  • $E-F=$ "The person we pick is younger than $35$ but their age is not a prime number".
  • $E\bigtriangleup F=$ "The person we pick is younger than $35$ or their age is a prime number, but not both".

The only operation we haven't mentioned is the complement of a set $E$, but we can think of that as the difference between $\Omega$ and $E$.

For example if we want the person picked being older than $29$, we can think of the event $E'=\Omega-E=\{30,31,32,...,65\}$.

One final remark about events: we can think of an outcome as the event that only contains that outcome, so we can limit ourselves to think about probabilities of events, since $P(\omega)=P(\{w\})$.

In further videos we will also learn how to calculate probabilities of simple and combined events. But know, let's go and do some exercises!

Notebooks AI
Notebooks AI Profile20060