stat841f11

From statwiki
Revision as of 03:03, 26 September 2011 by Sleigh (talk | contribs) (Case 2)
Jump to: navigation, search

Editor Sign Up

STAT 441/841 / CM 463/763 - Tuesday, 2011/09/20

Wiki Course Notes

Students will need to contribute to the wiki for 20% of their grade. Access via wikicoursenote.com Go to editor sign-up, and use your UW userid for your account name, and use your UW email.

primary (10%) Post a draft of lecture notes within 48 hours. You will need to do this 1 or 2 times, depending on class size.

secondary (10%) Make improvements to the notes for at least 60% of the lectures. More than half of your contributions should be technical rather than editorial. There will be a spreadsheet where students can indicate what they've done and when. The instructor will conduct random spot checks to ensure that students have contributed what they claim.


Classification

Definitions

classification: Predict a discrete random variable [math]Y[/math] (a label) by using another random variable [math]X[/math] (new data point) picked iid from a distribution

[math]X_i = (X_{i1}, X_{i2}, ... X_{id}) \in \mathcal{X} \subset \mathbb{R}^d[/math] ([math]d[/math]-dimensional vector) [math]Y_i[/math] in some finite set [math]\mathcal{Y}[/math]


classification rule: [math]h : \mathcal{X} \rightarrow \mathcal{Y}[/math] Take new observation [math]X[/math] and use a classification function [math]h(x)[/math] to generate a label [math]Y[/math]. In other words, If we fit the function [math]h(x)[/math] with a random variable [math]X[/math], it generates the label [math]Y[/math] which is the class to which we predict [math]X[/math] belongs.

Example: Let [math] \mathcal{X}[/math] be a set of 2D images and [math]\mathcal{Y}[/math] be a finite set of people. We want to learn a classification rule [math]h:\mathcal{X}\rightarrow\mathcal{Y}[/math] that with small true error predicts the person who appears in the image.


true error rate for classifier [math]h[/math] is the error with respect to the underlying distribution (that we do not know).

[math]L(h) = P(h(X) \neq Y )[/math]


empirical error rate (or training error rate) is the amount of error that our classification function [math]h(x)[/math] makes on the training data.

[math]\hat{L}_n(h) = (1/n) \sum_{i=1}^{n} \mathbf{I}(h(X_i) \neq Y_i)[/math]

where [math]\mathbf{I}()[/math] is an indicator function. Indicator function is defined by

[math]\mathbf{I}(x) = \begin{cases} 1 & \text{if } x \text{ is true} \\ 0 & \text{if } x \text{ is false} \end{cases}[/math]

So in this case [math]\mathbf{I}(h(X_i)\neq Y_i) = 1[/math] when [math]h(X_i)\neq Y_i[/math] i.e. when misclassifications happens.

e.g., 100 new data points with known (true) labels

[math]y_1 = h(x_1)[/math]

...

[math]y_{100} = h(x_{100})[/math]

To calculate the empirical error we count how many labels our function [math]h(x)[/math] assigned incorrectly and divide by n=100

Bayes Classifier

First recall Bayes' Rule, in the format [math]P(Y|X) = \frac{P(X|Y) P(Y)} {P(X)} [/math]

P(Y|X)  : posterior , probability of [math]Y[/math] given [math]X[/math]

P(X|Y)  : likelihood, probability of [math]X[/math] generating [math]Y[/math] or probability of [math]Y[/math] being generated by [math]X[/math]

P(Y)  : prior, probability of [math]Y[/math] being selected

P(X)  : marginal, probability of obtaining [math]X[/math]


We will start with the simplest case: [math]\mathcal{Y} = \{0,1\}[/math]

[math] r(x) = P(Y=1|X=x) = \frac{P(X=x|Y=1) P(Y=1)} {P(X=x)} = \frac{P(X=x|Y=1) P(Y=1)} {P(X=x|Y=1) P(Y=1) + P(X=x|Y=0) P(Y=0)}[/math]

Bayes' rule can be approached by computing either:

  • the posterior: P(Y=1|X=x) and P(Y=0|X=x) or
  • the likelihood: P(X=x|Y=1) and P(X=x|Y=0)

The former reflects a Bayesian approach - based on the degree of belief. The latter reflects a Frequentist approach - based on the frequency of observation.

There was some class discussion on which approach should be used. Both the ease of computation and the validity of both approaches were discussed. Overall, frequentists consider X to be a random variable. But they do not consider Y to be a random variable, because it has to take on one of the values from a fixed set (in the above case it would be either 0 or 1 and there is only one correct label for a given value X=x). Thus, from a frequentist's perspective it does not make sense to talk about the probability of Y.

This is actually a grey area and sometimes Bayesians and Frequentists use each others' approaches. So using Bayes' rule doesn't necessarily mean you're a Bayesian. Overall, the question remains unresolved.


The Bayes Classifier uses [math]P(Y=1|X=x)[/math]

[math] P(Y=1|X=x) = \frac{P(X=x|Y=1) P(Y=1)} {P(X=x|Y=1) P(Y=1) + P(X=x|Y=0) P(Y=0)}[/math]

P(Y=1) : the prior, based on belief/evidence beforehand

denominator : marginalized by summation

[math]h(x) = \begin{cases} 1 \ \ \hat{r}(x) \gt 1/2 \\ 0 \ \ otherwise \end{cases} [/math]

The set [math]\mathcal{D}(h) = \{ x : P(Y=1|X=x) = P(Y=0|X=x)... \} [/math]

which defines a decision boundary.


Theorem: Bayes rule is optimal. I.e., if h is any other classification rule, then [math]L(h^*) \lt = L(h)[/math] (This is to be proved in homework.)

Therefore, Why do we need any other method? A: Because X densities are often/typically unknown. I.e., [math]f_k(x)[/math] and/or [math]\pi_k[/math] unknown.

[math]P(Y=k|X=x) = \frac{P(X=x|Y=k)P(Y=k)} {P(X=x)} = \frac{f_k(x) \pi_k} {\sum_k f_k(x) \pi_k}[/math] f_k(x) is referred to as the class conditional distribution (~likelihood).

Therefore, we rely on some data to estimate quantities.

Three Main Approaches

1. Empirical Risk Minimization: Choose a set of classifier H (e.g., line, neural network) and find [math]h^* \in H[/math] that minimizes (some estimate of) L(h).

2. Regression: Find an estimate ([math]\hat{r}[/math]) of function [math]r[/math] and define [math]h(x) = \begin{cases} 1 \ \ \hat{r}(x) \gt 1/2 \\ 0 \ \ otherwise \end{cases} [/math]

The [math] 1/2 [/math] in the expression above is a threshold set for the regression prediction output.

In general regression refers to finding a continuous, real valued y. The problem here is more difficult, because of the restricted domain (y is a set of discrete label values).

3. Density Estimation: Estimate [math]P(X=x|Y=0)[/math] from [math]X_i[/math]'s for which [math]Y_i = 0[/math] Estimate [math]P(X=x|Y=1)[/math] from [math]X_i[/math]'s for which [math]Y_i = 1[/math] and let [math]P(Y=?) = (1/n) \sum_{i=1}^{n} Y_i[/math]

Define [math]\hat{r}(x) = \hat{P}(Y=1|X=x)[/math] and [math]h(x) = \begin{cases} 1 \ \ \hat{r}(x) \gt 1/2 \\ 0 \ \ otherwise \end{cases} [/math]

It is possible that there may not be enough data to estimate from for density estimation. But the main problem lies with high dimensional spaces, as the estimation results may not be good (high error rate) and sometimes even infeasible. The term curse of dimensionality was coined by Bellman <ref>R. E. Bellman, Dynamic Programming. Princeton University Press, 1957</ref> to describe this problem.

As the dimension of the space goes up, the learning requirements go up exponentially.


Multi-Class Classification

Generalize to case Y takes on k>2 values.


Theorem: [math]Y \in \mathcal{Y} = {1,2,..., k}[/math] optimal rule

[math]h*(x) = argmax_k P[/math]

where [math]P(Y=k|X=x) = \frac{f_k(x) \pi_k} {\sum_r f_r \pi_r}[/math]

LDA and QDA

(linear discriminant analysis, and quadratic discriminant analysis)

Simplest: Use approach 3 (above) and assume a parametric model for densities. Assume class conditional is Gaussian.

LDA (also known as FDA (Fisher's), which is in fact not really the same thing)

[math]\mathcal{Y} = \{ 0,1 \}[/math] assumed (i.e., 2 labels)

[math]h(x) = \begin{cases} 1 \ \ P(Y=1|X=x) \gt P(Y=0|X=x) \\ 0 \ \ otherwise \end{cases} [/math]

[math]P(Y=1|X=x) = \frac{f_1(x) \pi_1} {\sum_k f_k \pi_k} \ \ [/math] (denom = P(x))

1) Assume Gaussian distributions

[math]f_k(x) = \frac{1}{(2\pi)^{-d/2} |\Sigma_k|^{-1/2}} exp(-(1/2)(\mathbf{x} - \mathbf{\mu_k}) \Sigma_k^{-1}(\mathbf{x}-\mathbf{\mu_k}) )[/math]

must compare [math]\frac{f_1(x) \pi_1} {p(x)}[/math] with [math]\frac{f_0(x) \pi_0} {p(x)}[/math] Note that the p(x) denom can be ignored: [math]f_1(x) \pi_1[/math] with [math]f_0(x) \pi_0 [/math]

To find the decision boundary, set [math]f_1(x) \pi_1 = f_0(x) \pi_0 [/math]

2) Assume [math]\Sigma_1 = \Sigma_0[/math], we can use [math]\Sigma = \Sigma_0 = \Sigma_1[/math].

Cancel [math](2\pi)^{-d/2} |\Sigma_k|^{-1/2}[/math] from both sides.

Take log of both sides.

Subtract one side from both sides, leaving zero on one side.


[math]-(1/2)(\mathbf{x} - \mathbf{\mu_1})^T \Sigma^{-1} (\mathbf{x}-\mathbf{\mu_1}) + log(\pi_1) - [-(1/2)(\mathbf{x} - \mathbf{\mu_0})^T \Sigma^{-1} (\mathbf{x}-\mathbf{\mu_0}) + log(\pi_0)] = 0 [/math]


[math](1/2)[-\mathbf{x}^T \Sigma^{-1}\mathbf{x} - \mathbf{\mu_1}^T \Sigma^{-1} \mathbf{\mu_1} + 2\mathbf{\mu_1}^T \Sigma^{-1} \mathbf{x} + \mathbf{x}^T \Sigma^{-1}\mathbf{x} + \mathbf{\mu_0}^T \Sigma^{-1} \mathbf{\mu_0} - 2\mathbf{\mu_0}^T \Sigma^{-1} \mathbf{x} ] + log(\pi_1/\pi_0) = 0 [/math]


Cancelling out the terms quadratic in [math]\mathbf{x}[/math] and rearranging results in

[math](1/2)[-\mathbf{\mu_1}^T \Sigma^{-1} \mathbf{\mu_1} + \mathbf{\mu_0}^T \Sigma^{-1} \mathbf{\mu_0} + (2\mathbf{\mu_1}^T \Sigma^{-1} - 2\mathbf{\mu_0}^T \Sigma^{-1}) \mathbf{x}] + log(\pi_1/\pi_0) = 0 [/math]


And we see that the first pair of terms is constant, and the second pair is linear on x. So that we end up with something of the form [math]ax + b = 0[/math].

If we relax assumption 2 (eg. [math]\Sigma_1 != \Sigma_0[/math]) then we get a quadratic equation that can be written as [math]{x}^Ta{x}+b{x} + c = 0[/math]

Generalizing LDA and QDA

Theorem:


Suppose that [math]\,Y \in \{1,\dots,K\}[/math], if [math]\,f_k(x) = Pr(X=x|Y=k)[/math] is Gaussian, the Bayes Classifier rule is

[math]\,h^*(x) = \arg\max_{k} \delta_k(x)[/math]

Where

[math] \,\delta_k(x) = - \frac{1}{2}log(|\Sigma_k|) - \frac{1}{2}(x-\mu_k)^\top\Sigma_k^{-1}(x-\mu_k) + log (\pi_k) [/math]

When the Gaussian variances are equal [math]\Sigma_1 = \Sigma_0[/math] (e.g. LDA), then

[math] \,\delta_k(x) = x^\top\Sigma^{-1}\mu_k - \frac{1}{2}\mu_k^\top\Sigma^{-1}\mu_k + log (\pi_k) [/math]

In practice

We estimate the prior to be the chance that a random item from the collection belongs to set k, e.g.

[math]\,\hat{\pi_k} = \hat{Pr}(y=k) = \frac{n_k}{n}[/math]

The mean to be the average item in set k, e.g.

[math]\,\hat{\mu_k} = \frac{1}{n_k}\sum_{i:y_i=k}x_i[/math]

and calculate the covariance of each class e.g.

[math]\,\hat{\Sigma_k} = \frac{1}{n_k}\sum_{i:y_i=k}(x_i-\hat{\mu_k})(x_i-\hat{\mu_k})^\top[/math]

If we wish to use LDA we must calculate a common covariance, so we average all the covariances e.g.

[math]\,\Sigma=\frac{\sum_{r=1}^{k}(n_r\Sigma_r)}{n} [/math]

Where: [math]\,n_r[/math] is the number of data points in class [math]\,r[/math], [math]\,\Sigma_r[/math] is the covariance of class [math]\,r[/math], [math]\,n[/math] is the total number of data points, and [math]\,k[/math] is the number of classes.

Computation

For QDA we need to calculate: [math] \,\delta_k(x) = - \frac{1}{2}log(|\Sigma_k|) - \frac{1}{2}(x-\mu_k)^\top\Sigma_k^{-1}(x-\mu_k) + log (\pi_k) [/math]

Lets first consider when [math]\, \Sigma_k = I, \forall k [/math]. This is the case where each distribution is spherical, around the mean point.

Case 1

When [math]\, \Sigma_k = I [/math]

We have:

[math] \,\delta_k = - \frac{1}{2}log(|I|) - \frac{1}{2}(x-\mu_k)^\top I(x-\mu_k) + log (\pi_k) [/math]

but [math]\ \log(|I|)=\log(1)=0 [/math]

and [math]\, (x-\mu_k)^\top I(x-\mu_k) = (x-\mu_k)^\top(x-\mu_k) [/math] is the squared Euclidean distance between two points [math]\,x[/math] and [math]\,\mu_k[/math]

Thus in this condition, a new point can be classified by its distance away from the center of a class, adjusted by some prior.

Case 2

When [math]\, \Sigma_k \neq I [/math]

Using the Singular Value Decomposition(SVD) of [math]\, \Sigma_k[/math] we get [math] \, \Sigma_k = U_kS_kV_k^\top[/math]

but since [math]\, \Sigma[/math] is symmetric<ref> http://en.wikipedia.org/wiki/Covariance_matrix#Properties </ref> [math] \, \Sigma_k = U_kS_kU_k^\top [/math]

For [math]\,\delta_k[/math], the second term becomes what is also known as the Mahalanobis distance <ref>P. C. Mahalanobis, "On The Generalised Distance in Statistics," Proceedings of the National Institute of Sciences of India, 1936</ref> :

[math]\begin{align} (x-\mu_k)^\top\Sigma_k^{-1}(x-\mu_k)&= (x-\mu_k)^\top U_kS_k^{-1}U_k^T(x-\mu_k)\\ & = (U_k^\top x-U_k^\top\mu_k)^\top S_k^{-1}(U_k^\top x-U_k^\top \mu_k)\\ & = (U_k^\top x-U_k^\top\mu_k)^\top S_k^{-\frac{1}{2}}S_k^{-\frac{1}{2}}(U_k^\top x-U_k^\top\mu_k) \\ & = (S_k^{-\frac{1}{2}}U_k^\top x-S_k^{-\frac{1}{2}}U_k^\top\mu_k)^\top I(S_k^{-\frac{1}{2}}U_k^\top x-S_k^{-\frac{1}{2}}U_k^\top \mu_k) \\ & = (S_k^{-\frac{1}{2}}U_k^\top x-S_k^{-\frac{1}{2}}U_k^\top\mu_k)^\top(S_k^{-\frac{1}{2}}U_k^\top x-S_k^{-\frac{1}{2}}U_k^\top \mu_k) \\ \end{align} [/math]

If we think of [math] \, S_k^{-\frac{1}{2}}U_k^\top [/math] as a linear transformation that takes points in class [math]\,k[/math] and distributes them spherically around a point, like in case 1. Thus when we are given a new point, we can apply the modified [math]\,\delta_k[/math] values to calculate [math]\ h^*(\,x)[/math]. After applying the singular value decomposition, [math]\,\Sigma_k^{-1}[/math] is considered to be an identity matrix such that

[math] \,\delta_k = - \frac{1}{2}log(|I|) - \frac{1}{2}[(S_k^{-\frac{1}{2}}U_k^\top x-S_k^{-\frac{1}{2}}U_k^\top\mu_k)^\top(S_k^{-\frac{1}{2}}U_k^\top x-S_k^{-\frac{1}{2}}U_k^\top \mu_k)] + log (\pi_k) [/math]

and,

[math]\ \log(|I|)=\log(1)=0 [/math]

For applying the above method with classes that have different covariance matrices (for example the covariance matrices [math]\ \Sigma_0 [/math] and [math]\ \Sigma_1 [/math] for the two class case), each of the covariance matrices has to be decomposed using SVD to find the according transformation. Then, each new data point has to be transformed using each transformation to compare its distance to the mean of each class (for example for the two class case, the new data point would have to be transformed by the class 1 transformation and then compared to [math]\ \mu_0 [/math] and the new data point would also have to be transformed by the class 2 transformation and then compared to [math]\ \mu_1 [/math]).

References

<references />

Jgpitt - 2011/09/21