Advertisement
elena1234

Normal Distribution in Python

Jul 4th, 2022
857
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import seaborn as sns
  4. from scipy.stats import norm
  5.  
  6. # Perfume bottles are filled with the average volume of 150cc and the standard deviation of 2cc. What percent of bottles will have the # volume more than 153cc?
  7. mu = 150
  8. std = 2
  9. 1 - norm.cdf(153, mu, std)
  10.  
  11. # Perfume bottles are filled with the average volume of 150cc and the standard deviation of 2cc. What percent of bottles will have the # volume between 148 and 152cc?
  12. left_side = norm.cdf(148, mu, std)
  13. right_side = 1 - norm.cdf(152, mu, std)
  14. result = 1 - left_side - right_side
  15. result
  16.  
  17. # What percent of bottles will have the volume exactly 150cc?
  18. result = norm.pdf(150,mu,std)
  19. result
  20.  
  21. # What percent of bottles will have the volume less than 150cc?
  22. norm.cdf(150,mu,std)
  23.  
  24. # Visualization
  25. x_ax = np.linspace(144,156,130)
  26. y_ax = norm.pdf(x_ax, mu,std)
  27. sns.lineplot(x=x_ax, y = y_ax)
  28. plt.axvline(153, color = 'red')
  29. plt.show()
Advertisement
RAW Paste Data Copied
Advertisement