在 Python 中使用贝叶斯定理求解概率
Solving probability using Bayes Theorem in Python
我有以下问题:
Suppose that a given coin is known to be either a fair coin or else a biased coin such as that described in part a). Although you do not know which it is, you assign a prior probability of 0.8 to the hypothesis that the coin is fair.
The coin is tossed and lands heads. Use Bayes’ theorem to determine the probability that the coin is fair and the probability that the coin is biased* given this observation.
The Theorem is as follows:
P(A|B) = P(B|A) / P(B) * P(A)
下面的代码是我的尝试,但我收到一条错误消息,说我不能使用“|”带花车:
print(((0.2|0.8) / 0.2) * 0.8)
运算符“|”被称为 "binary OR" 并且它是一个二元运算符,不适用于浮点数。
另外,P(B|A)是单概率,读作"Probability of B given condition A happening."不是“|”的单一概率。为了使贝叶斯定理起作用,您需要有 3 个输入,而不是两个。
我有以下问题:
Suppose that a given coin is known to be either a fair coin or else a biased coin such as that described in part a). Although you do not know which it is, you assign a prior probability of 0.8 to the hypothesis that the coin is fair.
The coin is tossed and lands heads. Use Bayes’ theorem to determine the probability that the coin is fair and the probability that the coin is biased* given this observation.
The Theorem is as follows:
P(A|B) = P(B|A) / P(B) * P(A)
下面的代码是我的尝试,但我收到一条错误消息,说我不能使用“|”带花车:
print(((0.2|0.8) / 0.2) * 0.8)
运算符“|”被称为 "binary OR" 并且它是一个二元运算符,不适用于浮点数。
另外,P(B|A)是单概率,读作"Probability of B given condition A happening."不是“|”的单一概率。为了使贝叶斯定理起作用,您需要有 3 个输入,而不是两个。