ML7 - Baysian models

1. Bayesian Machine Learning

What is Bayesian machine learning?

简单来说Bayesian Machine Learning是建立于贝叶斯定理(Bayesian Machine Learning)上的统计模型的范例(paradigm)
p(\theta | x) = \frac{p(x | \theta) p(\theta)}{p(x)}
Bayesian ML的目的是给定likelihoodp(x | \theta)和prior distributionp(\theta)去估计posterior distribution p(\theta | x)。 likelihood是可以从训练数据中估计出来的。

Frequentist Vs Bayesian

  • Frequentist: 模型参数为固定数值。There exists a perfect model. ( such as MLE and MAP)
  • Bayesian: 模型参数是具有分布的随机变量。No perfect model.

举linear regression的例子,简单来说,传统的OLS regression就是践行了Frequentist的理念,也就是通过MLE给出线性回归模型的参数\beta的point estimator。

然而,Bayesian linear regression践行了Bayesian的理念。它是给出一个posterior distribution p(\beta| X), 也就是一个后验分布,而不是一个点估计。

而且,我们可以通过MAP去找到一个optimal \beta。(注:在posterior distribution上执行MAP等价于执行一个有regularization的MLE。Bayesian linear regression相当于Ridge regression。)

2. Bayes Theorem

(\theta | x) = \frac{p(x | \theta) p(\theta)}{p(x)}

背后的intuition是:

比如,在Bayesian Linear Regression中:

  1. Priors: If we have domain knowledge, or a guess for what the model parameters should be, we can include them in our model, unlike in the frequentist approach which assumes everything there is to know about the parameters comes from the data. If we don’t have any estimates ahead of time, we can use non-informative priors for the parameters such as a normal distribution.

  2. Posterior: The result of performing Bayesian Linear Regression is a distribution of possible model parameters based on the data and the prior. This allows us to quantify our uncertainty about the model: if we have fewer data points, the posterior distribution will be more spread out.

上面这个公式概括了Bayes Theorem的世界观:我们从初始估计(prior)开始,随着我们收集更多的证据(likelihood),我们的模型变得错误更少。贝叶斯推理是我们直觉的自然延伸。通常,我们有一个初始假设,当我们收集数据来支持或否定我们的想法时,我们改变了我们的世界模式。

而且随着数据量的增加,likelihood会"冲掉"prior,并且在数据量趋向于无穷的情况下,我们估计的参数会收敛到OLS获得的值。

3. Naive Bayes Classifier

Naive Bayes Classifier是Bayes Theorem在classification task中的一个应用。

假设

特征之间的conditional independence
argmax_{H} P(H\mid D)\\ = argmax_{H} P(H)P(D\mid H)

本质上Naive Bayes Classifier首先估计出prior probability p(H)和likelihood p(X|H)(likelihood在training data上由MLE估计出),然后通过Bayes Theorem计算出不同class的posterior probabilityp(H | X),最后通过MAP得出optimal class。

种类

两种NB的本质区别在于对feature分布的假设,导致对likelihood的计算方式不同。

  • Gaussian NB
  • Multinomial NB

参数设置

Additive Smoothing


4. Bayes linear regression

Bayes Linear Regression 的线性假设不变,同时一般假设error term服从均值为0的高斯分布:

y = \bf x^{T} {\bf \theta} + \epsilon\\ \epsilon \sim N(0, \sigma^2_y)

与OLS不同的是,Bayes Linear Regression会对参数的先验分布(priors)做出假设。这个prior distribution其实理论上可以是任意一种分布,但是我们一般假设为高斯分布:
\mathbf{\theta}\sim\mathcal{N}(\mathbf{0}, \tau_0^2\mathbf{I}_{d \times d})

于是,根据Bayes Theorem可以求出参数的后验分布:
\underbrace{p(\bf \theta| \bf y,X)}_{\text{posterior}} \propto \underbrace{ p(\bf y | X, \bf \theta)}_{\text{likelihood}} \; \underbrace{p(\theta)}_{\text{priors}}
其中p(\theta)是关于的函数;p(\bf y | X, \bf \theta)是关于training set中yX(都是已知的),以及\theta的函数。

最后我们经过计算可以得出posterior服从高斯分布:
p(\bf \theta| X, {\bf y}) \sim {\cal N}(\theta_n , V_n )

从这里我们可以看出,Bayes Linear Regression得出的是参数的一个分布。(注:这个时候,后验分布是直接得出的,但是大多数时候后验分布没有那么容易有一个公式给你,而需要借助sampling,比如Markov Chain Monte Carlo methods去得出后验分布。)

当我们要预测新数据点的值的时候,其实并不是给出一个预测值,而是给出的预测分布:
\begin{eqnarray} p(y_{new} | x_{new}, {\bf D}) &=& \int p({\bf y}_{new}| {\bf x}_{new}, {\bf \theta} ) p(\bf \theta| D)d\theta \nonumber \\ &=& \mathcal{N}(y_{new}|x_{new}^T\theta_n, \sigma_y^2+x_{new}^T\mathbf{V}_nx_{new}) \end{eqnarray}

参考网站

[1] What is Bayesian machine learning?: https://algorithmia.com/blog/bayesian-machine-learning#:~:text=Bayesian%20ML%20is%20a%20paradigm,models%20based%20on%20Bayes'%20Theorem.&text=Think%20about%20a%20standard%20machine,determine%20some%20mapping%20between%20them.

[2] Bayes linear regression: https://towardsdatascience.com/introduction-to-bayesian-linear-regression-e66e60791ea7

[3] Bayes linear regression: https://stats.stackexchange.com/questions/252577/bayes-regression-how-is-it-done-in-comparison-to-standard-regression

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 目录0 前言1 Discriminative Classifiers 1.1 Logistic Regressi...
    starryMia阅读 3,607评论 0 0
  • 久违的晴天,家长会。 家长大会开好到教室时,离放学已经没多少时间了。班主任说已经安排了三个家长分享经验。 放学铃声...
    飘雪儿5阅读 12,225评论 16 22
  • 今天感恩节哎,感谢一直在我身边的亲朋好友。感恩相遇!感恩不离不弃。 中午开了第一次的党会,身份的转变要...
    余生动听阅读 13,599评论 0 11
  • 在妖界我有个名头叫胡百晓,无论是何事,只要找到胡百晓即可有解决的办法。因为是只狐狸大家以讹传讹叫我“倾城百晓”,...
    猫九0110阅读 8,958评论 7 3
  • 彩排完,天已黑
    刘凯书法阅读 9,781评论 1 3

友情链接更多精彩内容