{"id":525,"date":"2017-01-07T12:48:17","date_gmt":"2017-01-07T12:48:17","guid":{"rendered":"http:\/\/muthu.co\/?p=525"},"modified":"2021-05-24T03:50:19","modified_gmt":"2021-05-24T03:50:19","slug":"poisson-distribution-with-python","status":"publish","type":"post","link":"http:\/\/write.muthu.co\/poisson-distribution-with-python\/","title":{"rendered":"Poisson distribution with Python"},"content":{"rendered":"\n

A Poisson distribution is the probability distribution of independent occurrences in an interval. Poisson distribution is used for count-based distributions where these events happen with a known average rate and independently of the time since the last event. For example, If the average number of cars that cross a particular street in a day is 25, then you can find the probability of 28 cars passing the street using the poisson formula given by.<\/p>\n\n\n\n

\"\"<\/a><\/figure><\/div>\n\n\n\n

e<\/em> is the base of natural logarithms (2.7183)
\u03bc is the mean number of occurrences (25 in this case)
x is the number of occurrences in question (28 in this case)<\/p>\n\n\n\n

At any day we can see 0,1,2,3,….25.. 30.. numbers on cars on the street with an average of around 25 cars. So to find 28 cars we would have to calculate<\/p>\n\n\n\n

\"\"<\/a><\/figure><\/div>\n\n\n\n

With the Poisson function, we define the mean value, which is 25 cars. The python function gives the probability, which is around (0.0632) 6%, that 28 cars will pass the street.<\/p>\n\n\n\n

The formula may seem complicated to solve through hands but with python libraries its a piece of cake.<\/p>\n\n\n\n

from scipy.stats import poisson\nimport matplotlib.pyplot as plt\nplt.ylabel('Probability of car passing')\nplt.xlabel('Number of cars')\nplt.title('Probability Distribution Curve')\narr = []\nrv = poisson(25)\nfor num in range(0,40):\n arr.append(rv.pmf(num))\n \n# print(rv.pmf(28))\nprob = rv.pmf(28)\nplt.grid(True)\nplt.plot(arr, linewidth=2.0)\nplt.plot([28], [prob], marker='o', markersize=6, color=\"red\")\nplt.show()<\/code><\/pre>\n\n\n\n

The output plot:<\/p>\n\n\n\n

\"\"<\/a><\/figure><\/div>\n\n\n\n
\n
\n

References:
https:\/\/www.umass.edu\/wsp\/resources\/poisson\/
http:\/\/matplotlib.org\/users\/pyplot_tutorial.html<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"

A Poisson distribution is the probability distribution of independent occurrences in an interval. Poisson distribution is used for count-based distributions where these events happen with a known average rate and independently of the time since the last event. For example, If the average number of cars that cross a particular street in a day is 25, […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,32,31],"tags":[54,58,62],"_links":{"self":[{"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/posts\/525"}],"collection":[{"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/comments?post=525"}],"version-history":[{"count":3,"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/posts\/525\/revisions"}],"predecessor-version":[{"id":1903,"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/posts\/525\/revisions\/1903"}],"wp:attachment":[{"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/media?parent=525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/categories?post=525"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/tags?post=525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}