Python Tutorial : Probability mass and distribution functions

DataCamp · Beginner ·🔢 Mathematical Foundations ·6y ago

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 SQL Server Tutorial: Date manipulation
SQL Server Tutorial: Date manipulation
DataCamp
2 R Tutorial: Intermediate Interactive Data Visualization with plotly in R
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
3 R Tutorial: Adding aesthetics to represent a variable
R Tutorial: Adding aesthetics to represent a variable
DataCamp
4 R Tutorial: Moving Beyond Simple Interactivity
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
5 Python Tutorial: Why use ML for marketing? Strategies and use cases
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
6 Python Tutorial: Preparation for modeling
Python Tutorial: Preparation for modeling
DataCamp
7 Python Tutorial: Machine Learning modeling steps
Python Tutorial: Machine Learning modeling steps
DataCamp
8 R Tutorial: The prior model
R Tutorial: The prior model
DataCamp
9 R Tutorial: Data & the likelihood
R Tutorial: Data & the likelihood
DataCamp
10 R Tutorial: The posterior model
R Tutorial: The posterior model
DataCamp
11 R Tutorial: An Introduction to plotly
R Tutorial: An Introduction to plotly
DataCamp
12 R Tutorial: Plotting a single variable
R Tutorial: Plotting a single variable
DataCamp
13 R Tutorial: Bivariate graphics
R Tutorial: Bivariate graphics
DataCamp
14 Python Tutorial: Customer Segmentation in Python
Python Tutorial: Customer Segmentation in Python
DataCamp
15 Python Tutorial: Time cohorts
Python Tutorial: Time cohorts
DataCamp
16 Python Tutorial: Calculate cohort metrics
Python Tutorial: Calculate cohort metrics
DataCamp
17 Python Tutorial: Cohort analysis visualization
Python Tutorial: Cohort analysis visualization
DataCamp
18 R Tutorial: Building Dashboards with flexdashboard
R Tutorial: Building Dashboards with flexdashboard
DataCamp
19 R Tutorial: Anatomy of a flexdashboard
R Tutorial: Anatomy of a flexdashboard
DataCamp
20 R Tutorial: Layout basics
R Tutorial: Layout basics
DataCamp
21 R Tutorial: Advanced layouts
R Tutorial: Advanced layouts
DataCamp
22 Python Tutorial: Time Series Analysis in Python
Python Tutorial: Time Series Analysis in Python
DataCamp
23 Python Tutorial: Correlation of Two Time Series
Python Tutorial: Correlation of Two Time Series
DataCamp
24 Python Tutorial: Simple Linear Regressions
Python Tutorial: Simple Linear Regressions
DataCamp
25 Python Tutorial: Autocorrelation
Python Tutorial: Autocorrelation
DataCamp
26 R Tutorial: The gapminder dataset
R Tutorial: The gapminder dataset
DataCamp
27 R Tutorial: The filter verb
R Tutorial: The filter verb
DataCamp
28 R Tutorial: The arrange verb
R Tutorial: The arrange verb
DataCamp
29 R Tutorial: The mutate verb
R Tutorial: The mutate verb
DataCamp
30 R Tutorial: What is cluster analysis?
R Tutorial: What is cluster analysis?
DataCamp
31 R Tutorial: Distance between two observations
R Tutorial: Distance between two observations
DataCamp
32 R Tutorial: The importance of scale
R Tutorial: The importance of scale
DataCamp
33 R Tutorial: Measuring distance for categorical data
R Tutorial: Measuring distance for categorical data
DataCamp
34 Python Tutorial: Plotting multiple graphs
Python Tutorial: Plotting multiple graphs
DataCamp
35 Python Tutorial: Customizing axes
Python Tutorial: Customizing axes
DataCamp
36 Python Tutorial: Legends, annotations, & styles
Python Tutorial: Legends, annotations, & styles
DataCamp
37 Python Tutorial: Introduction to iterators
Python Tutorial: Introduction to iterators
DataCamp
38 Python Tutorial: Playing with iterators
Python Tutorial: Playing with iterators
DataCamp
39 Python Tutorial: Using iterators to load large files into memory
Python Tutorial: Using iterators to load large files into memory
DataCamp
40 SQL Tutorial: Introduction to Relational Databases in SQL
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
41 SQL Tutorial: Tables: At the core of every database
SQL Tutorial: Tables: At the core of every database
DataCamp
42 SQL Tutorial: Update your database as the structure changes
SQL Tutorial: Update your database as the structure changes
DataCamp
43 Python Tutorial: Classification-Tree Learning
Python Tutorial: Classification-Tree Learning
DataCamp
44 Python Tutorial: Decision-Tree for Classification
Python Tutorial: Decision-Tree for Classification
DataCamp
45 Python Tutorial: Decision-Tree for Regression
Python Tutorial: Decision-Tree for Regression
DataCamp
46 Python Tutorial: Census Subject Tables
Python Tutorial: Census Subject Tables
DataCamp
47 Python Tutorial: Census Geography
Python Tutorial: Census Geography
DataCamp
48 Python Tutorial: Using the Census API
Python Tutorial: Using the Census API
DataCamp
49 R Tutorial: A/B Testing in R
R Tutorial: A/B Testing in R
DataCamp
50 R Tutorial: Baseline Conversion Rates
R Tutorial: Baseline Conversion Rates
DataCamp
51 R Tutorial: Designing an Experiment - Power Analysis
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
52 R Tutorial: Introduction to qualitative data
R Tutorial: Introduction to qualitative data
DataCamp
53 R Tutorial: Understanding your qualitative variables
R Tutorial: Understanding your qualitative variables
DataCamp
54 R Tutorial: Making Better Plots
R Tutorial: Making Better Plots
DataCamp
55 SQL Tutorial: OLTP and OLAP
SQL Tutorial: OLTP and OLAP
DataCamp
56 SQL Tutorial: Storing data
SQL Tutorial: Storing data
DataCamp
57 SQL Tutorial: Database design
SQL Tutorial: Database design
DataCamp
58 Python Tutorial: Introduction to spaCy
Python Tutorial: Introduction to spaCy
DataCamp
59 Python Tutorial: Statistical Models
Python Tutorial: Statistical Models
DataCamp
60 Python Tutorial: Rule-based Matching
Python Tutorial: Rule-based Matching
DataCamp

This video tutorial teaches you how to calculate probability distributions using Python, covering key concepts such as probability mass functions and cumulative distribution functions, with practical examples using the SciPy stats library.

Key Takeaways
  1. Define a discrete random variable
  2. Calculate the probability mass function
  3. Plot the probability mass function
  4. Calculate the cumulative distribution function
  5. Use the SciPy stats library to calculate probabilities
  6. Apply the binomial CDF to calculate probabilities
  7. Calculate the complement using the survival function
💡 The probability mass function and cumulative distribution function are essential tools for calculating probabilities in discrete random variables, and can be applied using Python with the SciPy stats library.

Related Reads

Up next
How to Open OSM Files (OpenStreetMap Data)
File Extension Geeks
Watch →