11 minute read

总结自 Bayesian Interpretation for Ridge Regression and the Lasso, Section 6.2.2 The Lasso, An Introduction to Statistical Learning.

水略深所以单独开一篇。


1. 啥是 BayesPermalink

1.1. DictionaryPermalink

  • Bayes: [ˈbeɪz]
  • a priori: [ˌɑpriˈɔri], from Latin a priori (“former”), literally “from the former”.
    • (logic) Based on hypothesis rather than experiment
      • 翻译成 “先验的” 应该是指 before experiment 的意思
      • A priori knowledge or justification is independent of experience (for example “All bachelors are unmarried”). 有一种 “显而易见,无需证明” 的感觉。
    • Presumed without analysis
      • One assumes, a priori, that a parent would be better at dealing with problems, 想当然地
  • a posteriori: [ˌɑpɒsteriˈɔ:rɪ] or [ˌeɪpɒsteriˈɔ:raɪ], from Latin a posteriori (“latter”), literally “from the latter”.
    • Relating to or derived by reasoning from observed facts; Empirical
      • A posteriori knowledge or justification is dependent on experience or empirical evidence (for example “Some bachelors I have met are very happy”).
      • What Locke calls “knowledge” they have called “a priori knowledge”; what he calls “opinion” or “belief” they have called “a posteriori” or “empirical knowledge”.
  • prior: [ˈpraɪə(r)]
  • posterior: [pɒˈstɪəriə(r)]

1.2. 绝好的科普文Permalink

这篇 数学之美番外篇:平凡而又神奇的贝叶斯方法 写得不能更好。在此摘录个贝叶斯方法的历史:

所谓的贝叶斯方法源于他生前为解决一个 “逆概率” 问题写的一篇文章,而这篇文章是在他死后才由他的一位朋友 Richard Price 发表出来的。在贝叶斯写这篇文章之前,人们已经能够计算 “正向概率”,如 “假设袋子里面有N个白球,M个黑球,你伸手进去摸一把,摸出黑球的概率是多大”。而一个自然而然的问题是反过来:”如果我们事先并不知道袋子里面黑白球的比例,而是闭着眼睛摸出一个(或好几个)球,观察这些取出来的球的颜色之后,那么我们可以就此对袋子里面的黑白球的比例作出什么样的推测”。这个问题,就是所谓的逆概率问题。

1.3 Bayes’ theorem 的变形Permalink

不禁想吐槽一下,在 Conditional Probability 里你就没有发现能把 P(B|A)=P(BA)P(A) 用到贝叶斯公式里么……

我们只变化贝叶斯公式的分母部分:

P(B|A)=P(A|B)P(B)P(A|B)P(B)+P(A|Bc)P(Bc)=P(A|B)P(B)P(AB)+P(ABc)(1.1)=P(A|B)P(B)P(A)

还是以摸球为例:

  • B: 袋子里黑白球的比例是 blah blah blah
  • A: 在不知道袋子里面黑白球比例的情况下,摸了 xxx 个球,yyy 个白的,zzz 个黑的

再根据这篇 Understand Bayes Theorem (prior/likelihood/posterior/evidence),有:

  • p(B|A) is posterior (probablity) distribution
    • the probablity of B posterior to (after) the observation of A
    • 注意我们这里不说 p(B|A) 是 posterior probablity。因为严格说来 p(B|A) 是一个分布律,是一个概率函数,从定义上说是一个分布,而不是一个具体的概率值。当然你理解成一个概率值也无可厚非。prior 同。
  • p(A|B) is likelihood
    • reversely, when B happened, how likely will A happen?
    • 从 1.4 来看,似乎不能直接叫 likelihood,待调查
  • p(B) is prior (probablity) distribution
    • prior to (before) any observation, what is the chance of B?
  • p(A) is the probablity of evidence
    • A 是已经发生的,是事实,是我们推测 B 的 evidence

如果忽略掉 evidence 的话(它是个常数),我们可以得到:

(1.2)posteriorprior×likelihood

读作 is proportional to 或 varies as。

yx simply means that y=kx for some constant k. (符号解释摘自 List of mathematical symbols)

1.4 在 regression 中的应用Permalink

根据这篇 Likelihood Function Confusions 讲义,一种常见的形式如:

  • Y: the observed data
  • θ: the parameters
  • P(Y|θ): the joint distribution of the sample, which is proportional to the likelihood function
  • P(θ): the prior distribution of the parameters

2. Bayesian Interpretation for Ridge Regression and the LassoPermalink

书上的写法有一点奇怪。按照 Bayesian Interpretations of Regularization 这篇讲义的说法:

  • p(Y|X,β) is the joint distribution over outputs Y given inputs X and the parameters β.
  • The likelihood of any fixed parameter vector β is L(β|X)=p(Y|X,β)

剩下的部分直接看 P226 好了。Bayesian Interpretations of Regularization 这篇讲义上有些推导过程,很有帮助。

3. Exercise 7Permalink

We will now derive the Bayesian connection to the lasso and ridge regression discussed in Section 6.2.2.

(a) QuestionPermalink

Suppose that yi=β0+j=1pxijβj+ϵi where ϵ1,,ϵn are independent and identically distributed from a N(0,σ2) distribution. Write out the likelihood for the data.

(a) AnswerPermalink

The likelihood for the data is:

L(θ|β)=p(β|θ)=p(β1|θ)××p(βn|θ)=i=1np(βi|θ)=i=1n1σ2πexp(|Yi(β0+j=1pβjXij)|22σ2)=(1σ2π)nexp(12σ2i=1n|Yi(β0+j=1pβjXij)|2)

(b) QuestionPermalink

Assume the following prior for β: β1,,βp are independent and identically distributed according to a double-exponential distribution with mean 0 and common scale parameter b: i.e. p(β)=12bexp(|β|b). Write out the posterior for β in this setting.

(b) AnswerPermalink

The posterior with double exponential (Laplace Distribution) with mean 0 and common scale parameter b, i.e. p(β)=12bexp(|β|/b) is:

f(β|X,Y)f(Y|X,β)p(β|X)=f(Y|X,β)p(β)

Substituting our values from (a) and our density function gives us:

f(Y|X,β)p(β)=(1σ2π)nexp(12σ2i=1n|Yi(β0+j=1pβjXij)|2)(12bexp(|β|b))=(1σ2π)n(12b)exp(12σ2i=1n|Yi(β0+j=1pβjXij)|2|β|b)

(c) QuestionPermalink

Argue that the lasso estimate is the mode for β under this posterior distribution.

(c) AnswerPermalink

Showing that the Lasso estimate for β is the mode under this posterior distribution is the same thing as showing that the most likely value for β is given by the lasso solution with a certain λ.

We can do this by taking our likelihood and posterior and showing that it can be reduced to the canonical Lasso Equation 6.7 from the book.

Let’s start by simplifying it by taking the logarithm of both sides:

log(f(Y|X,β)p(β))=log[(1σ2π)n(12b)exp(12σ2i=1n|Yi(β0+j=1pβjXij)|2|β|b)]=log[(1σ2π)n(12b)](12σ2i=1n|Yi(β0+j=1pβjXij)|2+|β|b)

We want to maximize the posterior, this means:

argmaxβf(β|X,Y)=argmaxβlog[(1σ2π)n(12b)](12σ2i=1n|Yi(β0+j=1pβjXij)|2+|β|b)

Since we are taking the difference of two values, the maximum of this value is the equivalent to taking the difference of the second value in terms of β. This results in:

=argminβ12σ2i=1n[Yi(β0+j=1pβjXij)]2+|β|b=argminβ12σ2i=1n[Yi(β0+j=1pβjXij)]2+1bj=1p|βj|=argminβ12σ2(i=1n[Yi(β0+j=1pβjXij)]2+2σ2bj=1p|βj|)

By letting λ=2σ2b, we can see that we end up with:

=argminβi=1n[Yi(β0+j=1pβjXij)]2+λj=1p|βj|=argminβRSS+λj=1p|βj|

which we know is the Lasso from Equation 6.7 in the book. Thus we know that when the posterior comes from a Laplace distribution with mean zero and common scale parameter b, the mode for β is given by the Lasso solution when λ=2σ2b.

(d) QuestionPermalink

Now assume the following prior for β: β1,,βp are independent and identically distributed according to a normal distribution with mean zero and variance c. Write out the posterior for β in this setting.

(d) AnswerPermalink

The posterior distributed according to Normal distribution with mean 0 and variance c is:

f(β|X,Y)f(Y|X,β)p(β|X)=f(Y|X,β)p(β)

Our probability distribution function then becomes:

p(β)=i=1pp(βi)=i=1p12cπexp(βi22c)=(12cπ)pexp(12ci=1pβi2)

Substituting our values from (a) and our density function gives us:

f(Y|X,β)p(β)=(1σ2π)nexp(12σ2i=1n[Yi(β0+j=1pβjXij)]2)(12cπ)pexp(12ci=1pβi2)=(1σ2π)n(12cπ)pexp(12σ2i=1n[Yi(β0+j=1pβjXij)]212ci=1pβi2)

(e) QuestionPermalink

Argue that the ridge regression estimate is both the mode and the mean for β under this posterior distribution.

(e) AnswerPermalink

Like from part (c), showing that the Ridge Regression estimate for β is the mode and mean under this posterior distribution is the same thing as showing that the most likely value for β is given by the lasso solution with a certain λ.

We can do this by taking our likelihood and posterior and showing that it can be reduced to the canonical Ridge Regression Equation 6.5 from the book.

Once again, we can take the logarithm of both sides to simplify it:

log(f(Y|X,β)p(β))=(1σ2π)n(12cπ)pexp(12σ2i=1n[Yi(β0+j=1pβjXij)]212ci=1pβi2)=log[(1σ2π)n(12cπ)p](12σ2i=1n[Yi(β0+j=1pβjXij)]2+12ci=1pβi2)

We want to maximize the posterior, this means:

argmaxβf(β|X,Y)=argmaxβlog[(1σ2π)n(12cπ)p](12σ2i=1n[Yi(β0+j=1pβjXij)]2+12ci=1pβi2)

Since we are taking the difference of two values, the maximum of this value is the equivalent to taking the difference of the second value in terms of β. This results in:

=argminβ(12σ2i=1n[Yi(β0+j=1pβjXij)]2+12ci=1pβi2)=argminβ(12σ2)(i=1n[Yi(β0+j=1pβjXij)]2+σ2ci=1pβi2)

By letting λ=σ2c, we end up with:

=argminβ(12σ2)(i=1n[Yi(β0+j=1pβjXij)]2+λi=1pβi2)=argminβRSS+λi=1pβi2

which we know is the Ridge Regression from Equation 6.5 in the book. Thus we know that when the posterior comes from a normal distribution with mean zero and variance c, the mode for β is given by the Ridge Regression solution when λ=σ2c. Since the posterior is Gaussian, we also know that it is the posterior mean.

Comments