prob140
Tutorial!¶
This is a brief introduction to the functionality in prob140
! For an
interactive guide, see the examples notebook in the GitLab directory.
Table of Contents
Getting Started¶
Make sure you are on the most recent version of the prob140 library. See the installation guide for more directions.
If you are using an iPython notebook, use this as your first cell:
# HIDDEN
from datascience import *
from prob140 import *
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('fivethirtyeight')
You may want to familiarize yourself with Data8’s datascience
documentation first
Creating a Distribution¶
The prob140 library adds distribution methods to the default table class that you should already be familiar with. A distribution is defined as a 2-column table in which the first column represents the domain of the distribution while the second column represents the probabilities associated with each value in the domain.
You can specify a list or array to the methods domain and probability to specify those columns for a distribution
In [1]: from prob140 import *
In [2]: dist1 = Table().domain(make_array(2, 3, 4)).probability(make_array(0.25, 0.5, 0.25))
In [3]: dist1
Out[3]:
Value | Probability
2 | 0.25
3 | 0.5
4 | 0.25
We can also construct a distribution by explicitly assigning values for the domain but applying a probability function to the values of the domain
In [4]: def p(x):
...: return 0.25
...:
In [5]: dist2 = Table().domain(np.arange(1, 8, 2)).probability_function(p)
In [6]: dist2