了解贝叶斯定理
我正在研究朴素贝叶斯分类器的实现。 集体智能编程通过将贝叶斯定理描述为以下内容来介绍此主题:
Pr(A | B) = Pr(B | A) x Pr(A)/Pr(B)
以及与文档分类相关的具体示例:
Pr(Category | Document) = Pr(Document | Category) x Pr(Category) / Pr(Document)
我希望有人能向我解释一下这里使用的符号,Pr(A | B)
和 Pr(A)
是什么意思?它看起来像某种函数,但是管道(“|
”)是什么意思等等?
I'm working on an implementation of a Naive Bayes Classifier. Programming Collective Intelligence introduces this subject by describing Bayes Theorem as:
Pr(A | B) = Pr(B | A) x Pr(A)/Pr(B)
As well as a specific example relevant to document classification:
Pr(Category | Document) = Pr(Document | Category) x Pr(Category) / Pr(Document)
I was hoping someone could explain to me the notation used here, what do Pr(A | B)
and Pr(A)
mean? It looks like some sort of function but then what does the pipe ("|
") mean, etc?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
但以上是关于条件概率的计算。你想要的是一个分类器,它利用这个原理,根据之前的概率来决定某物是否属于某个类别。
有关完整示例,请参阅 http://en.wikipedia.org/wiki/Naive_Bayes_classifier
But the above is with respect to the calculation of conditional probability. What you want is a classifier, which uses this principle to decide whether something belongs to a category based on the previous probability.
See http://en.wikipedia.org/wiki/Naive_Bayes_classifier for a complete example
我认为他们已经让你了解了基础知识。
读作:给定 B 的 A 的概率等于给定 A 的 B 的概率乘以 A 的概率除以 B 的概率。通常当您可以测量 B 的概率并且试图找出 B 是否成立时使用它或者,换句话说,我们确实关心A,但我们可以更直接地衡量B,所以让我们从我们可以衡量的开始。
让我给你一个推导,使编写代码变得更容易。它来自Judea Pearl。我对此有些挣扎,但当我意识到 Pearl 如何帮助我们将理论转化为代码后,我的灵光就亮了。
先验赔率:
似然比:
后验赔率:
在英语中,我们说您对某件事感兴趣的赔率(H 表示假设)就是您发现某件事为真的次数除以您发现它不为真的次数。说实话。假设每天有 10,000 所房屋中有一所被抢劫。这意味着在不考虑任何其他证据的情况下,您有 1/10,000 的机会被抢劫。
下一步是衡量您正在查看的证据。当你的问题为真时看到你所看到的证据的概率是多少除以当你的问题不为真时看到你所看到的证据的概率。假设您听到防盗警报器响起。当警报应该响时(警报响起时有人打开窗户)与不应该响时(风将警报关闭),您多久会收到警报?如果窃贼触发警报的可能性为 95%,其他事物触发警报的可能性为 1%,则可能性为 95.0。
你的总体信念只是可能性 * 先验赔率。在这种情况下,它是:
我不知道这是否会让事情变得更清楚,但是使用一些代码来跟踪先前的赔率,其他代码来查看可能性,以及多一段代码来处理往往会更容易。结合这些信息。
I think they've got you covered on the basics.
reads: the probability of A given B is the same as the probability of B given A times the probability of A divided by the probability of B. It's usually used when you can measure the probability of B and you are trying to figure out if B is leading us to believe in A. Or, in other words, we really care about A, but we can measure B more directly, so let's start with what we can measure.
Let me give you one derivation that makes this easier for writing code. It comes from Judea Pearl. I struggled with this a little, but after I realized how Pearl helps us turn theory into code, the light turned on for me.
Prior Odds:
Likelihood Ratio:
Posterior Odds:
In English, we are saying that the odds of something you're interested in (H for hypothesis) are simply the number of times you find something to be true divided by the times you find it not to be true. So, say one house is robbed every day out of 10,000. That means that you have a 1/10,000 chance of being robbed, without any other evidence being considered.
The next one is measuring the evidence you're looking at. What is the probability of seeing the evidence you're seeing when your question is true divided by the probability of seeing the evidence you're seeing when your question is not true. Say you are hearing your burglar alarm go off. How often do you get that alarm when it's supposed to go off (someone opens a window when the alarm is on) versus when it's not supposed to go off (the wind set the alarm off). If you have a 95% chance of a burglar setting off the alarm and a 1% chance of something else setting off the alarm, then you have a likelihood of 95.0.
Your overall belief is just the likelihood * the prior odds. In this case it is:
I don't know if this makes it any more clear, but it tends to be easier to have some code that keeps track of prior odds, other code to look at likelihoods, and one more piece of code to combine this information.
我已经用Python实现了它。这很容易理解,因为贝叶斯定理的所有公式都在单独的函数中:
I have implemented it in Python. It's very easy to understand because all formulas for Bayes theorem are in separate functions:
Pr(A | B):A 的条件概率:即 A 的概率,假设我们只知道 B
Pr(A):A 的先验概率
Pr(A | B): Conditional probability of A : i.e. probability of A, given that all we know is B
Pr(A) : Prior probability of A
Pr 是概率,Pr(A|B) 是条件概率。
查看维基百科了解详细信息。
Pr is the probability, Pr(A|B) is the conditional probability.
Check wikipedia for details.
竖线 (|) 表示“给定”。
给定 B 时 A 的概率等于给定 A x Pr(A)/Pr(B) 时 B 的概率
the pipe (|) means "given".
The probability of A given B is equal to the probability of B given A x Pr(A)/Pr(B)
管道用于表示条件概率。
Pr(A | B) = 给定 B 时 A 的概率
示例:
假设您感觉不舒服,并且上网查找症状。互联网告诉您,如果您有这些症状,那么您就患有 XYZ 疾病。
在这种情况下:
Pr(A | B) 是您想要找出的内容,即:
鉴于您有某些症状,您患有 XYZ 的可能性。
Pr(A) 是患有 XYZ 疾病的概率
Pr(B) 是患有这些症状的概率
Pr(B | A) 是您从互联网上找到的,即:
鉴于您患有这种疾病,出现症状的可能性。
The pipe is used to represent conditional probability.
Pr(A | B) = Probability of A given B
Example:
Let's say you are not feeling well and you surf the web for the symptoms. And the internet tells you that if you have these symptoms then you have XYZ disease.
In this case:
Pr(A | B) is what you are trying to find out, which is:
The probability of you having XYZ GIVEN THAT you have certain symptoms.
Pr(A) is the probability of having the disease XYZ
Pr(B) is the probability of having those symptoms
Pr(B | A) is what you find out from the internet, which is:
The probability of having the symptoms GIVEN THAT you have the disease.