The probability of an event is a number between 0 and 1, where, roughly speaking, 0 indicates impossibility of the event and 1 indicates certainty. The higher the probability of an event, the more likely it is that the event will occur. A simple example is the tossing of a fair (unbiased) coin. Since the coin is fair, the two outcomes ("heads" and "tails") are both equally probable; the probability of "heads" equals the probability of "tails"; and since no other outcomes are possible, the probability of either "heads" or "tails" is 1/2 (which could also be written as 0.5 or 50%). --- Source
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
Consider the example of tossing a fair coin to root our vocabulary and symbols. We will say the probability of getting a head is the total ways for this event to happen divided by the number of all possible outcomes.
EXAMPLE I: A Fair Coin
With one fair coin, we have outcomes either heads or tails. The outcome of interest is either a heads or tails. We would say the probability of each is :
Note that these probabilities sum to 1.
EXAMPLE II: An Unfair Coin
An example of an unfair coin would be anything that does not have equal probability. For example:
import scipy.stats as stats
fig, ax = plt.subplots(1, 2, figsize = (20, 5))
fair_coin = stats.bernoulli(.5).pmf([0, 1])
ax[0].bar(['heads', 'tails'], fair_coin, color=['gray', 'white'], edgecolor = 'black')
ax[0].set_title('Probabilities for a Fair Coin');
unfair_coin = stats.bernoulli(.4).pmf([0, 1])
ax[1].bar(['heads', 'tails'], unfair_coin, color = ['gray', 'white'], edgecolor = 'black')
ax[1].set_title('Probabilities for an Unfair Coin');
We can describe this kind of event as a function. Specifically, a situation in which there are two possible outcomes with a probability attached to each. This is called a bernoulli distribution, and the functional form is:
In our example of an unfair coin, if we consider heads as 0 and tails as 1 (), we would have:
which equals 0.6. Similarly, the probability of a tails ():
which equals 0.4.
def bernoulli(k, p):
return p*k + (1-p)*(1 - k)
bernoulli(0, 0.4)
bernoulli(1, 0.4)