そこで、超幾何分布計算機(確率と統計)を作成することにしました。問題は、出力が常に0から1の間にあることです。したがって、Pythonは、出力値に応じて0または1に切り捨てます。
これが私のコードです
from combinatorics import combination
from combinatorics import permutation
from factorial import factorial
from decimal import Decimal
#Hypergeometric and Binomial Distributions!
def hypergeometric(N, n, r, k):
hyper = (combination(r, k) * combination(N - r, n - k))/(combination(N, n))
return hyper
pop = int(raw_input("What is the size of the population? "))
draws = int(raw_input("How many draws were there? "))
spop = int(raw_input("What is the smaller population? "))
success = int(raw_input("How many successes were there? "))
print Decimal(hypergeometric(pop, draws, spop, success))
10進モジュールをインポートしようとしましたが、正しく使用しているかどうか、またはそれが目的であるかどうかさえわかりません。どんな助けでも素晴らしいでしょう!
編集:例として、N = 15、n = 6、r = 5、およびk = 3に設定すると、答えは0に丸められます。代わりに、適切な答えを出力したいと思います:.2397802398。ありがとう!