【发布时间】:2021-05-28 07:37:24
【问题描述】:
“100道题,每道题有4个可能的答案。如果每道题随机选择答案,通过考试的概率是多少(获得40%以上)”
x = ?
n = 100
p = 0.25
计算 40% 或更少就像为 x 的值输入 40 一样简单,但我如何将其交换为 40% 或更多?我试过 -40、60、-60,但显然这是错误的。
代码
import scipy.stats as stats
cum_binomalpha = stats.binom.pmf(40, n=100, p=0.25)
print(round(cum_binomalpha, 6))
编辑 - 可爱的 DOVELY 解决方案
import scipy.stats as stats
cumm_binomalpha = stats.binom.cdf(39, n=100, p=0.25)
print (round(1-cumm_binomalpha, 6))
【问题讨论】:
-
P(X > k) = 1 - P(X <= k)您还需要使用 cdf 来计算累积概率,而不是 pmf。
标签: python python-3.x scipy statistics