Python Tutorial : Probability mass and distribution functions
Key Takeaways
The video tutorial covers probability mass and distribution functions using Python, specifically the probability mass function and cumulative distribution function for discrete random variables, with examples using the SciPy stats library.
Full Transcript
after conducting many random experiments you will notice that some outcomes are more likely than others this is called a probability distribution there are two important functions that are useful for probability calculations the probability mass function and the cumulative distribution function a discrete random variable has a finite number of possible outcomes the probability mass function allows you to calculate the probability of getting a particular outcome for a discrete random variable the binomial probability mass function allows you to calculate the probability of getting K heads from n coin flips with the probability of getting helps the formula multiplies the number of different ways you can get K successes out of n coin flips by the probability of success raised to the number of successes k by the probability of failure 1 minus P raised to the number of failures and minus K it's okay if you don't understand the formula right now with practice your intuition about this will grow if we plot the probability mass function of getting K heads out of 10 third coin flips you can see that 5 is the most likely outcome with the SyFy dot stats library we can use the Bynum the PMF function to calculate this probability if you use Bynum PMF with parameters K equals 2 N equals 10 and P equals 0.5 to get the probability of getting two heads from 10 flips of a fair coin that is 4% the probability of getting five heads from ten coin flips is almost 25% the probability of getting 50 heads out of 100 flips of a biased coin with 30% probability of getting heads is extremely small not even a 1% chance if instead you calculate the probability of getting sixty five heads from 100 flips of a biased coin with 70 percent probability of getting heads you see that it's almost five percent as n gets larger the probability of getting K heads become smaller for the same P if you instead want to calculate the probability of getting K or fewer heads from n throws you use the binomial probability distribution function which adds the probability of getting zero heads out of n flips getting heads once out of n flips and getting all the way up to K heads out of n flips the binomial probability distribution function allows us to calculate the cumulative probability of getting K heads or fewer from n coin flips with P probability of getting heads in Python we use the venom the CDF function with parameters K N and P adding the probabilities from the mass function we get the cumulative distribution function CDF this is a way of getting a range of probabilities rather than the probability of a single event with the SyFy the stats library we can use the binomial function to get such a probability using the same parameters if you use the binomial CDF with parameters K equals 5 N equals 10 and P equals 0.5 you get the probability of getting heads 5 times or fewer out of 10 flips which is 62% the probability of getting heads 50 times or fewer out of 100 flips a biased coin with 30% probability of getting heads is near 100% it's almost guaranteed the probability of getting heads more than fifty nine times from 100 flips of a biased coin with P equals 70% is 99% again it's almost certain what if we want the probability of getting heads more than K times this is called the complement and we get it by subtracting the CDF from one alternatively we can calculate the complement using the function Bynum dot s F with the same parameters s f stands for survival function which allows you to get tail probabilities or the complement in this case we've had some fun calculating probabilities now let's pray
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/foundations-of-probability-in-python at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
After conducting many random experiments, you will notice that some outcomes are more likely than others. This is called a probability distribution.
There are two important functions that are useful for probability calculations: the probability mass function and the cumulative distribution function.
A discrete random variable has a finite number of possible outcomes.
The probability mass function allows you to calculate the probability of getting a particular outcome for a discrete random variable.
The binomial probability mass function allows you to calculate the probability of getting k heads from n coin flips with p probability of getting heads.
The formula multiplies the number of different ways that you can get k successes out of n coin flips...
by the probability of success raised to the number of successes, k...
by the probability of failure, 1 - p, raised to the number of failures, n - k.
It's okay if you don't understand the formula right now. With practice, your intuition about this will grow.
If we plot the probability mass function of getting k heads out of 10 fair coin flips, you can see that 5 is the most likely outcome.
With the scipy dot stats library we can use the binom dot pmf function to calculate this probability.
If you use binom dot pmf with parameters k equals 2, n equals 10, and p equals 0.5 you get the probability of getting 2 heads from 10 flips of a fair coin -- that is, 4%.
The probability of getting 5 heads from 10 coin flips is almost 25%.
The probability of getting 50 heads out of 100 flips of a biased coin with 30% probability of getting heads is extremely small: not even a 1% chance.
If instead you calculate the probability of getting 65 heads from 100 flips of a biased coin with 70% probabili
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: Python for Data
View skill →Related Reads
🎓
Tutor Explanation
DeepCamp AI