karlakmkj

Probability Density Functions

Jul 26th, 2021 (edited)
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. import scipy.stats as stats
  2. '''
  3. Formula for calculating area under the graph for distribution
  4. stats.norm.cdf(x, loc, scale)
  5. where
  6.    x: the value of interest
  7.    loc: the mean of the probability distribution
  8.    scale: the standard deviation of the probability distribution
  9. '''
  10. # to calculate a randomly chosen woman is less than 175 cm tall.
  11. # given Normal(167.64, 8) - mean = 167.64, standard deviation = 8 cm
  12. prob = stats.norm.cdf(175, 167.64, 8)
  13. print(prob)
  14.  
  15. # given normal distribution with a mean of 20 degrees Celcius and a standard deviation of 3 degrees
  16. # calculate probability that the weather on a randomly selected day will be between 18 to 25 degrees
  17. temp_prob_1 = stats.norm.cdf(25, 20, 3) - stats.norm.cdf(18, 20, 3)
  18. print(temp_prob_1)
  19.  
  20. # calculate probability that the weather on a randomly selected day will be greater than 24 degrees Celsius.
  21. temp_prob_2 = 1 - stats.norm.cdf(24, 20, 3)
  22. print(temp_prob_2)
Add Comment
Please, Sign In to add comment