Docsity

Bayesian Classification and Regression - Lecture Notes | CS 5350, Exams of Computer Science

Toggle sidebar
bg1
Machine Learning (CS 5350/CS 6350) 09 Apr 2007
Bayesian classification and regression
Remember way back when we were talking about linear regression. In the probabilistic formulation, we
assumed that the response ywas given by w>x+, where ∼ Nor(0, σ2) was noise. This means that overall,
we have:
y|x, w, σ2∼ Nor(w>x, σ 2)(1)
Here, wis an unknown parameter. We want to treat it as a random variable. Thus, it needs a prior. We use
a zero-mean, isotropic Gaussian prior:
y|x, w, σ2∼ Nor(w>x, σ 2I)
w|λ∼ Nor(0, λ−1I)(2)
Here, we have represented the inverse variance of the prior as λ(inverse variance is also called precision).
Our eventual goal is a prediction distribution, but for now we will work on the posterior of w. Namely,
suppose that we observe (x1, y1),...,(xN, yN). We want the distribution:
p(w|x1:N, y1:N, σ2, λ) = 1
Zp(w|λ)Y
n
p(yn|w, xn, σ2)
=1
ZNor(w|λ)Y
n
Nor(yn|w>xn, σ2)
=1
ZNor(w|λ)Nor(Y|wX, σ2I)
We don’t immediate know Z, so we cannot explicitly compute this distribution. However, a Gaussian is a
conjugate prior to a Gaussian mean, so we believe that this should be available in closed form. It turns out
that the posterior is a Gaussian with mean and variance given by:
µpost = Σpost σ2X>Y
(Σpost)−1=λI +σ2X>X
If you remember from our discussion of linear regression, the ML weights were given by:
wML =X>X−1X>Y
This has the same form (modulo regularization) as the mean of the posterior of the weights. One big
advantage of the Bayesian treatment is that we also get the covariance of the weights: how sure are we
about this value. This becomes useful when considering the prediction distribution.
1
pf3
pf4

Partial preview of the text

Download Bayesian Classification and Regression - Lecture Notes | CS 5350 and more Exams Computer Science in PDF only on Docsity!

Machine Learning (CS 5350/CS 6350) 09 Apr 2007

Bayesian classification and regression

Remember way back when we were talking about linear regression. In the probabilistic formulation, we assumed that the response y was given by w>x + , where  ∼ Nor(0, σ^2 ) was noise. This means that overall, we have:

y | x, w, σ^2 ∼ Nor(w>x, σ^2 ) (1)

Here, w is an unknown parameter. We want to treat it as a random variable. Thus, it needs a prior. We use a zero-mean, isotropic Gaussian prior:

y | x, w, σ^2 ∼ Nor(w>x, σ^2 I) w | λ ∼ Nor(0, λ−^1 I)

Here, we have represented the inverse variance of the prior as λ (inverse variance is also called precision).

Our eventual goal is a prediction distribution, but for now we will work on the posterior of w. Namely, suppose that we observe (x 1 , y 1 ),... , (xN , yN ). We want the distribution:

p(w | x1:N , y1:N , σ^2 , λ) =

Z

p(w | λ)

n

p(yn | w, xn, σ^2 )

Z

Nor(w | λ)

n

Nor(yn | w>xn, σ^2 )

Z

Nor(w | λ)Nor(Y | wX, σ^2 I)

We don’t immediate know Z, so we cannot explicitly compute this distribution. However, a Gaussian is a conjugate prior to a Gaussian mean, so we believe that this should be available in closed form. It turns out that the posterior is a Gaussian with mean and variance given by:

μpost^ = Σpost^

σ^2 X>Y

(Σpost)−^1 = λI + σ^2 X>X

If you remember from our discussion of linear regression, the ML weights were given by:

wM L =

X>X

X>Y

This has the same form (modulo regularization) as the mean of the posterior of the weights. One big advantage of the Bayesian treatment is that we also get the covariance of the weights: how sure are we about this value. This becomes useful when considering the prediction distribution.

Usually we don’t care about the weights themselves, but care only about predictions. I.e., for a test point xN +1, we want to predict yN +1. That is, we want to compute:

p(yN +1 | x1:N +1, y1:N , σ^2 , λ) =

dwp(w | x1:N , y1:N , σ^2 , λ)p(yN +1 | xN +1, w, σ^2 )

We know that the posterior is Gaussian as is the conditional, so this is:

p(yN +1 | x1:N +1, y1:N , σ^2 , λ) =

dwNor(w | μpost, Σpost)Nor(yN +1 | w>xN +1, σ^2 )

Again, Gaussian is conjugate to Gaussian so we can compute this in closed form. This yields:

p(yN +1 | x1:N +1, y1:N , σ^2 , λ) = Nor(yN +1 | μpost>x, (σpred)^2 )

(σpred)^2 =

σ^2

  • xN +1>ΣpostxN +

So, what have we gained over standard linear regression? Not a whole lot – essentially, we get the same predictive mean, but now we can compute a variance on the prediction (how accurate do we think we are?). This doesn’t seem like a big win. However, an addition win is that we can often do “maximum likelihood II” esimation of the hyperparameters. Remember that usually we have to tune hyperparameters by cross-validation. In Bayesian land, we don’t have to. Maximum likelihood II says that we should set the hyperparameters (in this case, σ^2 and λ) to their maximum likelihood values, but where in this case the likelihood contains an integration. I.e., set them as follows:

ˆσ^2 , ˆλ = argmax σ^2 ,λ

dwNor(w | 0 , λI)Nor(X | wX, σ^2 I)

So although a “true Bayesian” might scoff at ML estimation, it tends to not be too bad for inferring higher- level values. We won’t go through this estimation (it’s actually not that hard), but since the distributions are conjugate, we get a closed form (Gaussian) for the evidence, and we can take gradients and optimize for the hyperparameters. To me, this is the big win of Bayesian approaches.

Let’s consider logistic regression. It will turn out that, due to the presence of the sigmoid function, the conjugacy of the Gaussian won’t work out. Here, we have:

y | x, w ∼ σ(w>x) w | λ−^1 ∼ Nor(0, λ−^1 I) (3)

Here, we have used a zero-mean Gaussian prior with isotropic precision λ as the prior. For N data points, we get:

p(w | x1:N , y1:N , λ−^1 ) =

Z

Nor(w | 0 , λ−^1 I)

n

σ(ynw>xn) (4)

Now we move to the multivariate case. This is essentially the same, but with vectors and matrices. We start with the approximation:

log f (θ) ≈ log f (θ 0 ) −

(θ − θ 0 )>Z(θ − θ 0 )>

θ 0 = argmax θ

f (θ)

A = −∇∇ log f (θ)|θ=θ 0

Aij =

∂^2

∂θiθj

log f (θ)

θ=θ 0

This again leads to a Gaussian approximation, with:

q(θ) =

[

det A (2π)M

] 1 / 2

exp

[

(θ − θ 0 )>A(θ − θ 0 )

]

= Nor(θ | θ 0 , A−^1 )

So the story is the same in the multivariate case. Compute the vector θ 0 that maximizes f (again, the MAP solution). Then compute A as a matrix of second derivatives. This yields a Gaussian approximation.

To apply the Laplace approximation to logistic regression, we have to follow two steps. First, we compute the MAP solution for the weights to obtain w 0. We already know how to compute the MAP (CS6350 students did it in HW1). The next step is to compute the matrix of second derivates (aka, the Hessian). This is given by:

A = λ +

n

yn(1 − yn)xnxn>

Thus, we obtain q(w) = Nor(w | w 0 , A).

Of course, we rarely care about w itself, but rather want to make predictions. This is, again, intractable. The standard solution (described in detail in the book) yields:

p(yN +1 = 1 | x1:N +1, y1:N , λ) =

dwσ(w>xN +1)p(w | x1:N , y1:N , λ)

dwσ(w>xN +1)Nor(w | w 0 , A)

≈ σ

([

π 8 xN +1>AxN +

]− 1 / 2

w 0 xN +

Note that the first term here is always positive, and the second term is just the standard MAP prediction. The first term serves to scale the uncertainty – if A is very uncertain, this value will be small and hence the resulting probability will be close to 0.5.