SHARE
TWEET

Untitled

a guest Oct 21st, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Exo 24
  2.  
  3. from scipy.stats import *
  4. # https://docs.scipy.org/doc/scipy/reference/stats.html
  5.  
  6. print("Loi uniforme discrete")
  7. # https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.randint.html#scipy.stats.randint
  8. # Exemple utilisation : dé/casino
  9. loi = randint(low=0,high=11) #low=0, prendre high=b+1
  10. print("P(X=0)",randint.pmf(k=0, low=0,high=11))
  11. print("P(X=2)",randint(low=0,high=11).pmf(2))
  12. print("P(X<=2)",loi.cdf(2))
  13. print("P(3<=X<=5)=P(X<=5)-P(X<=2)",loi.cdf(5)-loi.cdf(3-1))
  14. print("P(X<=9)",loi.cdf(9))
  15. print("E(X)",loi.mean())
  16. print("V(X)",loi.var())
  17.  
  18. print("--------------------")
  19.  
  20. print("Loi binomiale")
  21. # https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.binom.html#scipy-stats-binom
  22. # Exemple utilisation : tirage boule rouge/bleu
  23. loi = binom(n=6,p=0.7)
  24. print("P(X=0)",loi.pmf(0))
  25. print("P(X=2)",loi.pmf(2))
  26. print("P(X<=2)",loi.cdf(2))
  27. print("P(3<=X<=5)=P(X<=5)-P(X<=2)",loi.cdf(5)-loi.cdf(3-1))
  28. print("P(X<=5)",loi.cdf(5))
  29. print("E(X)",loi.mean())
  30. print("V(X)",loi.var())
  31.  
  32. print("--------------------")
  33.  
  34. print("Loi de Poisson")
  35. # https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.poisson.html#scipy.stats.poisson
  36. # Exemple d'utilisation : un évenement se reproduisent k fois durant une période
  37. loi = poisson(mu=2) #
  38. print("P(X=0)",loi.pmf(0))
  39. print("P(X=1)",loi.pmf(1))
  40. print("P(X<2)",loi.cdf(1)) # P(X<2) = P(X<=1)
  41. print("P(3<=X<=5)=P(X<=5)-P(X<=2)",loi.cdf(5)-loi.cdf(3-1))
  42. print("P(X>=2)",1-loi.cdf(1)) # P(X>=1) = 1 - (P(X<=1))
  43. print("E(X)",loi.mean()) # E(X) = n * p
  44. print("V(X)",loi.var()) # V(X) = n * p * (1 - p)
  45.  
  46. print("--------------------")
  47.  
  48. print("Loi Exponentielle")
  49. # https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.expon.html#scipy.stats.expon
  50. # Loi durée de vie sans vieillissement
  51. loi = expon(scale=1/3) # "3" c'est lambda
  52. print("P(X=0)",0) # Probabilité qu'un nombre X est 0
  53. print("P(X=1)",0)
  54. print("P(X<2)",loi.cdf(2)) # P(X<2) = P(X<=2)
  55. print("P(3<=X<=5)=P(X<=5)-P(X<=3)",loi.cdf(5)-loi.cdf(3))
  56. print("P(X>=2)",1-loi.cdf(2)) # P(X>=1) = 1 - (P(X<=1))
  57. print("E(X)",loi.mean()) # E(X) = n * p
  58. print("V(X)",loi.var()) # V(X) = n * p * (1 - p)
  59.  
  60. print("--------------------")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top