stat841f10

Proposal Fall 2010

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: Provide a summary for each topic here.. Please improve this article if you can. (October 8 2010) | small = | smallimage = | smallimageright = | smalltext = }}

Summary

Classification

Statistical classification, or simply known as classification, is an area of supervised learning that addresses the problem of how to systematically assign unlabeled (classes unknown) novel data to their labels (classes or groups or types) by using knowledge of their features (characteristics or attributes) that are obtained from observation and/or measurement. A classifier is a specific technique or method for performing classification. To classify new data, a classifier first uses labeled (classes are known) training data to train a model, and then it uses a function known as its classification rule to assign a label to each new data input after feeding the input's known feature values into the model to determine how much the input belongs to each class.

LDA x QDA

Linear discriminant analysis[1] is a statistical method used to find the linear combination of features which best separate two or more classes of objects or events. It is widely applied in classifying diseases, positioning, product management, and marketing research. LDA assumes that the different classes have the same covariance matrix $\, \Sigma$.

Quadratic Discriminant Analysis[2], on the other hand, aims to find the quadratic combination of features. It is more general than linear discriminant analysis. Unlike LDA, QDA does not make the assumption that the different classes have the same covariance matrix $\, \Sigma$. Instead, QDA makes the assumption that each class $\, k$ has its own covariance matrix $\, \Sigma_k$.

Principle Component Analysis

Principal component analysis (PCA) is a dimensionality-reduction method invented by Karl Pearson in 1901 [3]. Depending on where this methodology is applied, other common names of PCA include the Karhunen–Loève transform (KLT) , the Hotelling transform, and the proper orthogonal decomposition (POD). PCA is the simplist eigenvector-based multivariate analysis. It reduces the dimensionality of the data by revealing the internal structure of the data in a way that best explains the variance in the data. To this end, PCA works by using a user-defined number of the most important directions of variation (dimensions or principal components) of the data to project the data onto these directions so as to produce a lower-dimensional representation of the original data. The resulting lower-dimensional representation of our data is usually much easier to visualize and it also exhibits the most informative aspects (dimensions) of our data whilst capturing as much of the variation exhibited by our data as it possibly could.

Reference Textbook

The Elements of Statistical Learning: Data Mining, Inference, and Prediction, Second Edition, February 2009 Trevor Hastie, Robert Tibshirani, Jerome Friedman (3rd Edition is available)

Classification - September 21, 2010

Classification

Statistical classification, or simply known as classification, is an area of supervised learning that addresses the problem of how to systematically assign unlabeled (classes unknown) novel data to their labels (classes or groups or types) by using knowledge of their features (characteristics or attributes) that are obtained from observation and/or measurement. A classifier is a specific technique or method for performing classification. To classify new data, a classifier first uses labeled (classes are known) training data to train a model, and then it uses a function known as its classification rule to assign a label to each new data input after feeding the input's known feature values into the model to determine how much the input belongs to each class.

Classification has been an important task for people and society since the beginnings of history. According to this link, the earliest application of classification in human society was probably done by prehistory peoples for recognizing which wild animals were beneficial to people and which ones were harmful, and the earliest systematic use of classification was done by the famous Greek philosopher Aristotle (384 BC - 322 BC) when he, for example, grouped all living things into the two groups of plants and animals. Classification is generally regarded as one of four major areas of statistics, with the other three major areas being regression, clustering, and dimensionality reduction (feature extraction or manifold learning). Please be noted that some people consider classification to be a broad area that consists of both supervised and unsupervised methods of classifying data. In this view, as can be seen in this link, clustering is simply a special case of classification and it may be called unsupervised classification.

In classical statistics, classification techniques were developed to learn useful information using small data sets where there is usually not enough of data. When machine learning was developed after the application of computers to statistics, classification techniques were developed to work with very large data sets where there is usually too many data. A major challenge facing data mining using machine learning is how to efficiently find useful patterns in very large amounts of data. An interesting quote that describes this problem quite well is the following one made by the retired Yale University Librarian Rutherford D. Rogers, a link to a source of which can be found here.

       "We are drowning in information and starving for knowledge."
- Rutherford D. Rogers


In the Information Age, machine learning when it is combined with efficient classification techniques can be very useful for data mining using very large data sets. This is most useful when the structure of the data is not well understood but the data nevertheless exhibit strong statistical regularity. Areas in which machine learning and classification have been successfully used together include search and recommendation (e.g. Google, Amazon), automatic speech recognition and speaker verification, medical diagnosis, analysis of gene expression, drug discovery etc.

The formal mathematical definition of classification is as follows:

Definition: Classification is the prediction of a discrete random variable $\mathcal{Y}$ from another random variable $\mathcal{X}$, where $\mathcal{Y}$ represents the label assigned to a new data input and $\mathcal{X}$ represents the known feature values of the input.

A set of training data used by a classifier to train its model consists of $\,n$ independently and identically distributed (i.i.d) ordered pairs $\,\{(X_{1},Y_{1}), (X_{2},Y_{2}), \dots , (X_{n},Y_{n})\}$, where the values of the $\,ith$ training input's feature values $\,X_{i} = (\,X_{i1}, \dots , X_{id}) \in \mathcal{X} \subset \mathbb{R}^{d}$ is a d-dimensional vector and the label of the $\, ith$ training input is $\,Y_{i} \in \mathcal{Y}$ that can take a finite number of values. The classification rule used by a classifier has the form $\,h: \mathcal{X} \mapsto \mathcal{Y}$. After the model is trained, each new data input whose feature values is $\,x$ is given the label $\,\hat{Y}=h(x)$.

As an example, if we would like to classify some vegetables and fruits, then our training data might look something like the one shown in the following picture from Professor Ali Ghodsi's Fall 2010 STAT 841 slides.

After we have selected a classifier and then built our model using our training data, we could use the classifier's classification rule $\ h$ to classify any newly-given vegetable or fruit such as the one shown in the following picture from Professor Ali Ghodsi's Fall 2010 STAT 841 slides after first obtaining its feature values.

As another example, suppose we wish to classify newly-given fruits into apples and oranges by considering three features of a fruit that comprise its color, its diameter, and its weight. After selecting a classifier and constructing a model using training data $\,\{(X_{color, 1}, X_{diameter, 1}, X_{weight, 1}, Y_{1}), \dots , (X_{color, n}, X_{diameter, n}, X_{weight, n}, Y_{n})\}$, we could then use the classifier's classification rule $\,h$ to assign any newly-given fruit having known feature values $\,x = (\,x_{color}, x_{diameter} , x_{weight})$ the label $\, \hat{Y}=h(x) \in \mathcal{Y}= \{apple,orange\}$.

Error rate

The empirical error rate (or training error rate) of a classifier having classification rule $\,h$ is defined as the frequency at which $\,h$ does not correctly classify the data inputs in the training set, i.e., it is defined as $\,\hat{L}_{n} = \frac{1}{n} \sum_{i=1}^{n} I(h(X_{i}) \neq Y_{i})$, where $\,I$ is an indicator variable and $\,I = \left\{\begin{matrix} 1 &\text{if } h(X_i) \neq Y_i \\ 0 &\text{if } h(X_i) = Y_i \end{matrix}\right.$. Here, $\,X_{i} \in \mathcal{X}$ and $\,Y_{i} \in \mathcal{Y}$ are the known feature values and the true class of the $\,ith$ training input, respectively.

The true error rate $\,L(h)$ of a classifier having classification rule $\,h$ is defined as the probability that $\,h$ does not correctly classify any new data input, i.e., it is defined as $\,L(h)=P(h(X) \neq Y)$. Here, $\,X \in \mathcal{X}$ and $\,Y \in \mathcal{Y}$ are the known feature values and the true class of that input, respectively.

In practice, the empirical error rate is obtained to estimate the true error rate, whose value is impossible to be known because the parameter values of the underlying process cannot be known but can only be estimated using available data. The empirical error rate, in practice, estimates the true error rate quite well in that, as mentioned here, it is an unbiased estimator of the true error rate.

Bayes Classifier

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: In response to the previous tag: The naive Bayes classifier is a special (simpler) case of the Bayes classifier. It uses an extra assumption: that the presence (or absence) of a particular feature of a class is unrelated to the presence (or absence) of any other feature. This assumption allows for an easier likelihood function $\,f_y(x)$ in the equation:

\begin{align} P(Y=y|X=x) &=\frac{f_y(x)\pi_y}{\Sigma_{\forall i \in \mathcal{Y}} f_i(x)\pi_i} \end{align}

The simper form of the likelihood function seen in the naive Bayes is:

\begin{align} f_y(x) = P(X=x|Y=y) = {\prod_{i=1}^{n} P(X_{i}=x_{i}|Y=y)} \end{align}

The Bayes classifier taught in class was not the naive Bayes classifier. Perhaps a comment should be made about the naive Bayes classifier in the body of the text. Please improve this article if you can. (October 14 2010) | small = | smallimage = | smallimageright = | smalltext = }}

A Bayes classifier is a simple probabilistic classifier based on applying Bayes' Theorem (from Bayesian statistics) with strong (naive) independence assumptions. A more descriptive term for the underlying probability model would be "independent feature model".

In simple terms, a Bayes classifier assumes that the presence (or absence) of a particular feature of a class is unrelated to the presence (or absence) of any other feature. For example, a fruit may be considered to be an apple if it is red, round, and about 4" in diameter. Even if these features depend on each other or upon the existence of the other features, a Bayes classifier considers all of these properties to independently contribute to the probability that this fruit is an apple.

Depending on the precise nature of the probability model, naive Bayes classifiers can be trained very efficiently in a supervised learning setting. In many practical applications, parameter estimation for Bayes models uses the method of maximum likelihood; in other words, one can work with the naive Bayes model without believing in Bayesian probability or using any Bayesian methods.

In spite of their design and apparently over-simplified assumptions, naive Bayes classifiers have worked quite well in many complex real-world situations. In 2004, analysis of the Bayesian classification problem has shown that there are some theoretical reasons for the apparently unreasonable efficacy of Bayes classifiers [1]. Still, a comprehensive comparison with other classification methods in 2006 showed that Bayes classification is outperformed by more current approaches, such as boosted trees or random forests[2].

An advantage of the naive Bayes classifier is that it requires a small amount of training data to estimate the parameters (means and variances of the variables) necessary for classification. Because independent variables are assumed, only the variances of the variables for each class need to be determined and not the entire covariance matrix.

After training its model using training data, the Bayes classifier classifies any new data input in two steps. First, it uses the input's known feature values and the Bayes formula to calculate the input's posterior probability of belonging to each class. Then, it uses its classification rule to place the input into the most-probable class, which is the one associated with the input's largest posterior probability.

In mathematical terms, for a new data input having feature values $\,(X = x)\in \mathcal{X}$, the Bayes classifier labels the input as $(Y = y) \in \mathcal{Y}$, such that the input's posterior probability $\,P(Y = y|X = x)$ is maximum over all of the members of $\mathcal{Y}$.

Suppose there are $\,k$ classes and we are given a new data input having feature values $\,x$. The following derivation shows how the Bayes classifier finds the input's posterior probability $\,P(Y = y|X = x)$ of belonging to each class $y \in \mathcal{Y}$.

\begin{align} P(Y=y|X=x) &= \frac{P(X=x|Y=y)P(Y=y)}{P(X=x)} \\ &=\frac{P(X=x|Y=y)P(Y=y)}{\Sigma_{\forall i \in \mathcal{Y}}P(X=x|Y=i)P(Y=i)} \end{align}

Here, $\,P(Y=y|X=x)$ is known as the posterior probability as mentioned above, $\,P(Y=y)$ is known as the prior probability, $\,P(X=x|Y=y)$ is known as the likelihood, and $\,P(X=x)$ is known as the evidence.

In the special case where there are two classes, i.e., $\, \mathcal{Y}=\{0, 1\}$, the Bayes classifier makes use of the function $\,r(x)=P\{Y=1|X=x\}$ which is the posterior probability of a new data input having feature values $\,x$ belonging to the class $\,Y = 1$. Following the above derivation for the posterior probabilities of a new data input, the Bayes classifier calculates $\,r(x)$ as follows:

\begin{align} 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)} \end{align}

The Bayes classifier's classification rule $\,h^*: \mathcal{X} \mapsto \mathcal{Y}$, then, is

$\, h^*(x)= \left\{\begin{matrix} 1 &\text{if } \hat r(x)\gt \frac{1}{2} \\ 0 &\mathrm{otherwise} \end{matrix}\right.$.

Here, $\,x$ is the feature values of a new data input and $\hat r(x)$ is the estimated value of the function $\,r(x)$ given by the Bayes classifier's model after feeding $\,x$ into the model. Still in this special case of two classes, the Bayes classifier's decision boundary is defined as the set $\,D(h)=\{x: P(Y=1|X=x)=P(Y=0|X=x)\}$. The decision boundary $\,D(h)$ essentially combines together the trained model and the decision function $\,h^*$, and it is used by the Bayes classifier to assign any new data input to a label of either $\,Y = 0$ or $\,Y = 1$ depending on which side of the decision boundary the input lies in. From this decision boundary, it is easy to see that, in the case where there are two classes, the Bayes classifier's classification rule can be re-expressed as

$\, h^*(x)= \left\{\begin{matrix} 1 &\text{if } P(Y=1|X=x)\gt P(Y=0|X=x) \\ 0 &\mathrm{otherwise} \end{matrix}\right.$.

Bayes Classification Rule Optimality Theorem The Bayes classifier is the optimal classifier in that it results in the least possible true probability of misclassification for any given new data input, i.e., for any generic classifier having classification rule $\,h$, it is always true that $\,L(h^*(x)) \le L(h(x))$. Here, $\,L$ represents the true error rate, $\,h^*$ is the Bayes classifier's classification rule, and $\,x$ is any given data input's feature values.

Although the Bayes classifier is optimal in the theoretical sense, other classifiers may nevertheless outperform it in practice. The reason for this is that various components which make up the Bayes classifier's model, such as the likelihood and prior probabilities, must either be estimated using training data or be guessed with a certain degree of belief. As a result, the estimated values of the components in the trained model may deviate quite a bit from their true population values, and this can ultimately cause the calculated posterior probabilities of inputs to deviate quite a bit from their true values. Estimation of all these probability functions, as likelihood, prior probability, and evidence function is a very expensive task, computationally, which also makes some other classifiers more favorable than Bayes classifier.

A detailed proof of this theorem is available here.

Defining the classification rule:

In the special case of two classes, the Bayes classifier can use three main approaches to define its classification rule $\,h^*$:

1) Empirical Risk Minimization: Choose a set of classifiers $\mathcal{H}$ and find $\,h^*\in \mathcal{H}$ that minimizes some estimate of the true error rate $\,L(h^*)$.
2) Regression: Find an estimate $\hat r$ of the function $x$ and define
$\, h^*(x)= \left\{\begin{matrix} 1 &\text{if } \hat r(x)\gt \frac{1}{2} \\ 0 &\mathrm{otherwise} \end{matrix}\right.$.
3) Density Estimation: Estimate $\,P(X=x|Y=0)$ from the $\,X_{i}$'s for which $\,Y_{i} = 0$, estimate $\,P(X=x|Y=1)$ from the $\,X_{i}$'s for which $\,Y_{i} = 1$, and estimate $\,P(Y = 1)$ as $\,\frac{1}{n} \sum_{i=1}^{n} Y_{i}$. Then, calculate $\,\hat r(x) = \hat P(Y=1|X=x)$ and define
$\, h^*(x)= \left\{\begin{matrix} 1 &\text{if } \hat r(x)\gt \frac{1}{2} \\ 0 &\mathrm{otherwise} \end{matrix}\right.$.

Typically, the Bayes classifier uses approach 3 to define its classification rule. These three approaches can easily be generalized to the case where the number of classes exceeds two.

Multi-class classification:

Suppose there are $\,k$ classes, where $\,k \ge 2$.

In the above discussion, we introduced the Bayes formula for this general case:

\begin{align} P(Y=y|X=x) &=\frac{P(X=x|Y=y)P(Y=y)}{\Sigma_{\forall i \in \mathcal{Y}}P(X=x|Y=i)P(Y=i)} \end{align}

which can re-worded as:

\begin{align} P(Y=y|X=x) &=\frac{f_y(x)\pi_y}{\Sigma_{\forall i \in \mathcal{Y}} f_i(x)\pi_i} \end{align}

Here, $\,f_y(x) = P(X=x|Y=y)$ is known as the likelihood function and $\,\pi_y = P(Y=y)$ is known as the prior probability.

In the general case where there are at least two classes, the Bayes classifier uses the following theorem to assign any new data input having feature values $\,x$ into one of the $\,k$ classes.

Theorem

Suppose that $\mathcal{Y}= \{1, \dots, k\}$, where $\,k \ge 2$. Then, the optimal classification rule is $\,h^*(x) = arg max_{i} P(Y=i|X=x)$, where $\,i \in \{1, \dots, k\}$.

Example: We are going to predict if a particular student will pass STAT 441/841. There are two classes represented by $\, \mathcal{Y}\in \{ 0,1 \}$, where 1 refers to pass and 0 refers to fail. Suppose that the prior probabilities are estimated or guessed to be $\,\hat P(Y = 1) = \hat P(Y = 0) = 0.5$. We have data on past student performances, which we shall use to train the model. For each student, we know the following:

Whether or not the student’s GPA was greater than 3.0 (G).
Whether or not the student had a strong math background (M).
Whether or not the student was a hard worker (H).
Whether or not the student passed or failed the course. Note: these are the known y values in the training data.

These known data are summarized in the following tables:

{{
Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: this graph is not complete, the reason is that it should be in consistent with the computation below.. Please improve this article if you can. (September 2010) | small = | smallimage = | smallimageright = | smalltext = }}

For each student, his/her feature values is $\, x = \{G, M, H\}$ and his or her class is $\, y \in \{0, 1\}$.

Suppose there is a new student having feature values $\, x = \{0, 1, 0\}$, and we would like to predict whether he/she would pass the course. $\,\hat r(x)$ is found as follows:

$\, \hat r(x) = P(Y=1|X =(0,1,0))=\frac{P(X=(0,1,0)|Y=1)P(Y=1)}{P(X=(0,1,0)|Y=0)P(Y=0)+P(X=(0,1,0)|Y=1)P(Y=1)}=\frac{0.05*0.5}{0.05*0.5+0.2*0.5}=\frac{0.025}{0.075}=\frac{1}{3}\lt \frac{1}{2}.$

The Bayes classifier assigns the new student into the class $\, h^*(x)=0$. Therefore, we predict that the new student would fail the course.

Bayesian vs. Frequentist

The Bayesian view of probability and the frequentist view of probability are the two major schools of thought in the field of statistics regarding how to interpret the probability of an event.

The Bayesian view of probability states that, for any event E, event E has a prior probability that represents how believable event E would occur prior to knowing anything about any other event whose occurrence could have an impact on event E's occurrence. Theoretically, this prior probability is a belief that represents the baseline probability for event E's occurrence. In practice, however, event E's prior probability is unknown, and therefore it must either be guessed at or be estimated using a sample of available data. After obtaining a guessed or estimated value of event E's prior probability, the Bayesian view holds that the probability, that is, the believability of event E's occurrence, can always be made more accurate should any new information regarding events that are relevant to event E become available. The Bayesian view also holds that the accuracy for the estimate of the probability of event E's occurrence is higher as long as there are more useful information available regarding events that are relevant to event E. The Bayesian view therefore holds that there is no intrinsic probability of occurrence associated with any event. If one adherers to the Bayesian view, one can then, for instance, predict tomorrow's weather as having a probability of, say, $\,50%$ for rain. The Bayes classifier as described above is a good example of a classifier developed from the Bayesian view of probability. The earliest works that lay the framework for the Bayesian view of probability is accredited to Thomas Bayes (1702–1761).

In contrast to the Bayesian view of probability, the frequentist view of probability holds that there is an intrinsic probability of occurrence associated with every event to which one can carry out many, if not an infinite number, of well-defined independent random trials. In each trial for an event, the event either occurs or it does not occur. Suppose $n_x$ denotes the number of times that an event occurs during its trials and $n_t$ denotes the total number of trials carried out for the event. The frequentist view of probability holds that, in the long run, where the number of trials for an event approaches infinity, one could theoretically approach the intrinsic value of the event's probability of occurrence to any arbitrary degree of accuracy, i.e., :$P(x) = \lim_{n_t\rightarrow \infty}\frac{n_x}{n_t}$. In practice, however, one can only carry out a finite number of trials for an event and, as a result, the probability of the event's occurrence can only be approximated as $P(x) \approx \frac{n_x}{n_t}$. If one adherers to the frequentist view, one cannot, for instance, predict the probability that there would be rain tomorrow. This is because one cannot possibly carry out trials for any event that is set in the future. The founder of the frequentist school of thought is arguably the famous Greek philosopher Aristotle. In his work Rhetoric, Aristotle gave the famous line "the probable is that which for the most part happens".

More information regarding the Bayesian and the frequentist schools of thought are available here. Furthermore, an interesting and informative youtube video that explains the Bayesian and frequentist views of probability is available here.

First, we shall limit ourselves to the case where there are two classes, i.e. $\, \mathcal{Y}=\{0, 1\}$. In the above discussion, we introduced the Bayes classifier's decision boundary $\,D(h^*)=\{x: P(Y=1|X=x)=P(Y=0|X=x)\}$, which represents a hyperplane that determines the class of any new data input depending on which side of the hyperplane the input lies in. Now, we shall look at how to derive the Bayes classifier's decision boundary under certain assumptions of the data. Linear discriminant analysis (LDA) and quadratic discriminant analysis (QDA) are two of the most well-known ways for deriving the Bayes classifier's decision boundary, and we shall look at each of them in turn.

Let us denote the likelihood $\ P(X=x|Y=y)$ as $\ f_y(x)$ and the prior probability $\ P(Y=y)$ as $\ \pi_y$.

First, we shall examine LDA. As explained above, the Bayes classifier is optimal. However, in practice, the prior and conditional densities are not known. Under LDA, one gets around this problem by making the assumptions that both of the two classes have multivariate normal (Gaussian) distributions and the two classes have the same covariance matrix $\, \Sigma$. Under the assumptions of LDA, we have: $\ P(X=x|Y=y) = f_y(x) = \frac{1}{ (2\pi)^{d/2}|\Sigma|^{1/2} }\exp\left( -\frac{1}{2} (x - \mu_k)^\top \Sigma^{-1} (x - \mu_k) \right)$. Now, to derive the Bayes classifier's decision boundary using LDA, we equate $\, P(Y=1|X=x)$ to $\, P(Y=0|X=x)$ and proceed from there. The derivation of $\,D(h^*)$ is as follows:

$\,Pr(Y=1|X=x)=Pr(Y=0|X=x)$
$\,\Rightarrow \frac{Pr(X=x|Y=1)Pr(Y=1)}{Pr(X=x)}=\frac{Pr(X=x|Y=0)Pr(Y=0)}{Pr(X=x)}$ (using Bayes' Theorem)
$\,\Rightarrow Pr(X=x|Y=1)Pr(Y=1)=Pr(X=x|Y=0)Pr(Y=0)$ (canceling the denominators)
$\,\Rightarrow f_1(x)\pi_1=f_0(x)\pi_0$
$\,\Rightarrow \frac{1}{ (2\pi)^{d/2}|\Sigma|^{1/2} }\exp\left( -\frac{1}{2} (x - \mu_1)^\top \Sigma^{-1} (x - \mu_1) \right)\pi_1=\frac{1}{ (2\pi)^{d/2}|\Sigma|^{1/2} }\exp\left( -\frac{1}{2} (x - \mu_0)^\top \Sigma^{-1} (x - \mu_0) \right)\pi_0$
$\,\Rightarrow \exp\left( -\frac{1}{2} (x - \mu_1)^\top \Sigma^{-1} (x - \mu_1) \right)\pi_1=\exp\left( -\frac{1}{2} (x - \mu_0)^\top \Sigma^{-1} (x - \mu_0) \right)\pi_0$
$\,\Rightarrow -\frac{1}{2} (x - \mu_1)^\top \Sigma^{-1} (x - \mu_1) + \log(\pi_1)=-\frac{1}{2} (x - \mu_0)^\top \Sigma^{-1} (x - \mu_0) +\log(\pi_0)$ (taking the log of both sides).
$\,\Rightarrow \log(\frac{\pi_1}{\pi_0})-\frac{1}{2}\left( x^\top\Sigma^{-1}x + \mu_1^\top\Sigma^{-1}\mu_1 - 2x^\top\Sigma^{-1}\mu_1 - x^\top\Sigma^{-1}x - \mu_0^\top\Sigma^{-1}\mu_0 + 2x^\top\Sigma^{-1}\mu_0 \right)=0$ (expanding out)
$\,\Rightarrow \log(\frac{\pi_1}{\pi_0})-\frac{1}{2}\left( \mu_1^\top\Sigma^{-1} \mu_1-\mu_0^\top\Sigma^{-1}\mu_0 - 2x^\top\Sigma^{-1}(\mu_1-\mu_0) \right)=0$ (canceling out alike terms and factoring).

It is easy to see that, under LDA, the Bayes's classifier's decision boundary $\,D(h^*)$ has the form $\,ax+b=0$ and it is linear in $\,x$. This is where the word linear in linear discriminant analysis comes from.

LDA under the two-classes case can easily be generalized to the general case where there are $\,k \ge 2$ classes. In the general case, suppose we wish to find the Bayes classifier's decision boundary between the two classes $\,m$ and $\,n$, then all we need to do is follow a derivation very similar to the one shown above, except with the classes $\,1$ and $\,0$ being replaced by the classes $\,m$ and $\,n$. Following through with a similar derivation as the one shown above, one obtains the Bayes classifier's decision boundary $\,D(h^*)$ between classes $\,m$ and $\,n$ to be $\,\log(\frac{\pi_m}{\pi_n})-\frac{1}{2}\left( \mu_m^\top\Sigma^{-1} \mu_m-\mu_n^\top\Sigma^{-1}\mu_n - 2x^\top\Sigma^{-1}(\mu_m-\mu_n) \right)=0$ . In addition, for any two classes $\,m$ and $\,n$ for whom we would like to find the Bayes classifier's decision boundary using LDA, if $\,m$ and $\,n$ both have the same number of data, then, in this special case, the resulting decision boundary would lie exactly halfway between the centers (means) of $\,m$ and $\,n$.

The Bayes classifier's decision boundary for any two classes as derived using LDA looks something like the one that can be found in this link:

Although the assumption under LDA may not hold true for most real-world data, it nevertheless usually performs quite well in practice, where it often provides near-optimal classifications. For instance, the Z-Score credit risk model that was designed by Edward Altman in 1968 and revisited in 2000, is essentially a weighted LDA. This model has demonstrated a 85-90% success rate in predicting bankruptcy, and for this reason it is still in use today.

According to this link, some of the limitations of LDA include:

• LDA implicitly assumes that the data in each class has a Gaussian distribution.
• LDA implicitly assumes that the mean rather than the variance is the discriminating factor.
• LDA may over-fit the training data.

Linear and Quadratic Discriminant Analysis cont'd - September 23, 2010

LDA x QDA

Linear discriminant analysis[4] is a statistical method used to find the linear combination of features which best separate two or more classes of objects or events. It is widely applied in classifying diseases, positioning, product management, and marketing research. LDA assumes that the different classes have the same covariance matrix $\, \Sigma$.

Quadratic Discriminant Analysis[5], on the other hand, aims to find the quadratic combination of features. It is more general than linear discriminant analysis. Unlike LDA, QDA does not make the assumption that the different classes have the same covariance matrix $\, \Sigma$. Instead, QDA makes the assumption that each class $\, k$ has its own covariance matrix $\, \Sigma_k$.

The derivation of the Bayes classifier's decision boundary $\,D(h^*)$ under QDA is similar to that under LDA. Again, let us first consider the two-classes case where $\, \mathcal{Y}=\{0, 1\}$. This derivation is given as follows:

$\,Pr(Y=1|X=x)=Pr(Y=0|X=x)$
$\,\Rightarrow \frac{Pr(X=x|Y=1)Pr(Y=1)}{Pr(X=x)}=\frac{Pr(X=x|Y=0)Pr(Y=0)}{Pr(X=x)}$ (using Bayes' Theorem)
$\,\Rightarrow Pr(X=x|Y=1)Pr(Y=1)=Pr(X=x|Y=0)Pr(Y=0)$ (canceling the denominators)
$\,\Rightarrow f_1(x)\pi_1=f_0(x)\pi_0$
$\,\Rightarrow \frac{1}{ (2\pi)^{d/2}|\Sigma_1|^{1/2} }\exp\left( -\frac{1}{2} (x - \mu_1)^\top \Sigma_1^{-1} (x - \mu_1) \right)\pi_1=\frac{1}{ (2\pi)^{d/2}|\Sigma_0|^{1/2} }\exp\left( -\frac{1}{2} (x - \mu_0)^\top \Sigma_0^{-1} (x - \mu_0) \right)\pi_0$
$\,\Rightarrow \frac{1}{|\Sigma_1|^{1/2} }\exp\left( -\frac{1}{2} (x - \mu_1)^\top \Sigma_1^{-1} (x - \mu_1) \right)\pi_1=\frac{1}{|\Sigma_0|^{1/2} }\exp\left( -\frac{1}{2} (x - \mu_0)^\top \Sigma_0^{-1} (x - \mu_0) \right)\pi_0$ (by cancellation)
$\,\Rightarrow -\frac{1}{2}\log(|\Sigma_1|)-\frac{1}{2} (x - \mu_1)^\top \Sigma_1^{-1} (x - \mu_1)+\log(\pi_1)=-\frac{1}{2}\log(|\Sigma_0|)-\frac{1}{2} (x - \mu_0)^\top \Sigma_0^{-1} (x - \mu_0)+\log(\pi_0)$ (by taking the log of both sides)
$\,\Rightarrow \log(\frac{\pi_1}{\pi_0})-\frac{1}{2}\log(\frac{|\Sigma_1|}{|\Sigma_0|})-\frac{1}{2}\left( x^\top\Sigma_1^{-1}x + \mu_1^\top\Sigma_1^{-1}\mu_1 - 2x^\top\Sigma_1^{-1}\mu_1 - x^\top\Sigma_0^{-1}x - \mu_0^\top\Sigma_0^{-1}\mu_0 + 2x^\top\Sigma_0^{-1}\mu_0 \right)=0$ (by expanding out)
$\,\Rightarrow \log(\frac{\pi_1}{\pi_0})-\frac{1}{2}\log(\frac{|\Sigma_1|}{|\Sigma_0|})-\frac{1}{2}\left( x^\top(\Sigma_1^{-1}-\Sigma_0^{-1})x + \mu_1^\top\Sigma_1^{-1}\mu_1 - \mu_0^\top\Sigma_0^{-1}\mu_0 - 2x^\top(\Sigma_1^{-1}\mu_1-\Sigma_0^{-1}\mu_0) \right)=0$

It is easy to see that, under QDA, the decision boundary $\,D(h^*)$ has the form $\,ax^2+bx+c=0$ and it is quadratic in $\,x$. This is where the word quadratic in quadratic discriminant analysis comes from.

As is the case with LDA, QDA under the two-classes case can easily be generalized to the general case where there are $\,k \ge 2$ classes. In the general case, suppose we wish to find the Bayes classifier's decision boundary between the two classes $\,m$ and $\,n$, then all we need to do is follow a derivation very similar to the one shown above, except with the classes $\,1$ and $\,0$ being replaced by the classes $\,m$ and $\,n$. Following through with a similar derivation as the one shown above, one obtains the Bayes classifier's decision boundary $\,D(h^*)$ between classes $\,m$ and $\,n$ to be $\,\log(\frac{\pi_m}{\pi_n})-\frac{1}{2}\log(\frac{|\Sigma_m|}{|\Sigma_n|})-\frac{1}{2}\left( x^\top(\Sigma_m^{-1}-\Sigma_n^{-1})x + \mu_m^\top\Sigma_m^{-1}\mu_m - \mu_n^\top\Sigma_n^{-1}\mu_n - 2x^\top(\Sigma_m^{-1}\mu_m-\Sigma_n^{-1}\mu_n) \right)=0$.

Summarizing LDA and QDA

We can summarize what we have learned so far into the following theorem.

Theorem:

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

$\,h^*(x) = \arg\max_{k} \delta_k(x)$

where,

• In the case of LDA, which assumes that a common covariance matrix is shared by all classes, $\,\delta_k(x) = x^\top\Sigma^{-1}\mu_k - \frac{1}{2}\mu_k^\top\Sigma^{-1}\mu_k + log (\pi_k)$, and the Bayes classifier's decision boundary $\,D(h^*)$ is linear in $\,x$.
• In the case of QDA, which assumes that each class has its own covariance matrix, $\,\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)$, and the Bayes classifier's decision boundary $\,D(h^*)$ is quadratic in $\,x$.

Note $\,\arg\max_{k} \delta_k(x)$returns the set of k for which $\,\delta_k(x)$ attains its largest value.

In practice

We need to estimate the prior, so in order to do this, we use the Maximum Likelihood estimates from the sample for $\,\pi,\mu_k,\Sigma_k$ in place of their true values, i.e.

File:estimation.png
Estimation of the probability of belonging to either class k or l

$\,\hat{\pi_k} = \hat{Pr}(y=k) = \frac{n_k}{n}$

$\,\hat{\mu_k} = \frac{1}{n_k}\sum_{i:y_i=k}x_i$

$\,\hat{\Sigma_k} = \frac{1}{n_k-d}\sum_{i:y_i=k}(x_i-\hat{\mu_k})(x_i-\hat{\mu_k})^\top$

Common covariance, denoted $\Sigma$, is defined as the weighted average of the covariance for each class.

In the case where we need a common covariance matrix, we get the estimate using the following equation:

$\,\Sigma=\frac{\sum_{r=1}^{k}(n_r\Sigma_r)}{n}$

Where: $\,n_r$ is the number of data points in class r, $\,\Sigma_r$ is the covariance of class r and $\,n$ is the total number of data points.

Computation For QDA And LDA

First, let us consider QDA, and examine each of the following two cases.

Case 1: (Example) $\, \Sigma_k = I$

$\, \Sigma_k = I$ for every class $\,k$ implies that our data is spherical. This means that the data of each class $\,k$ is distributed symmetrically around the center $\,\mu_k$, i.e. the isocontours are all circles.

We have:

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

We see that the first term in the above equation, $\,\frac{-1}{2}log(|I|)$, is zero since $\ |I|=1$. The second term contains $\, (x-\mu_k)^\top I(x-\mu_k) = (x-\mu_k)^\top(x-\mu_k)$, which is the squared Euclidean distance between $\,x$ and $\,\mu_k$. Therefore we can find the distance between a point and each center and adjust it with the log of the prior, $\,log(\pi_k)$. The class that has the minimum distance will maximize $\,\delta_k$. According to the theorem, we can then classify the point to a specific class $\,k$.

Case 2: (General Case) $\, \Sigma_k \ne I$

We can decompose this as:

$\, \Sigma_k = U_kS_kV_k^\top = U_kS_kU_k^\top$ (In general when $\,X=U_kS_kV_k^\top$, $\,U_k$ is the eigenvectors of $\,X_kX_k^T$ and $\,V_k$ is the eigenvectors of $\,X_k^\top X_k$. So if $\, X_k$ is symmetric, we will have $\, U_k=V_k$. Here $\, \Sigma_k$ is symmetric, because it is the covariance matrix of $X_k$) and the inverse of $\,\Sigma_k$ is

$\, \Sigma_k^{-1} = (U_kS_kU_k^\top)^{-1} = (U_k^\top)^{-1}S_k^{-1}U_k^{-1} = U_kS_k^{-1}U_k^\top$ (since $\,U_k$ is orthonormal)

So from the formula for $\,\delta_k$, the second term is

\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}

where we have the squared Euclidean distance between $\, S_k^{-\frac{1}{2}}U_k^\top x$ and $\, S_k^{-\frac{1}{2}}U_k^\top\mu_k$.

A transformation of all the data points can be done from $\,x$ to $\,x^*$ where $\, x^* \leftarrow S_k^{-\frac{1}{2}}U_k^\top x$.

A similar transformation of all the centers can be done from $\,\mu_k$ to $\,\mu_k^*$ where $\, \mu_k^* \leftarrow S_k^{-\frac{1}{2}}U_k^\top \mu_k$.

It is now possible to do classification with $\,x^*$ and $\,\mu_k^*$, treating them as in Case 1 above.

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: The sentence above may cause some misleading. In general case, $\,\Sigma_k$ may not be the same . So you can't treat them completely the same as in Case 1 above. You need to compute $\, log{|\Sigma_k |}$ differently. Here is a detailed discussion below:. Please improve this article if you can. (October 18 2010) | small = | smallimage = | smallimageright = | smalltext = }} {{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: The sentence above is right since by transforming$\,x$ to $\,x^*$ where $\, x^* \leftarrow S_k^{-\frac{1}{2}}U_k^\top x$, the new variable variance is $I$. Please improve this article if you can. (October 18 2010) | small = | smallimage = | smallimageright = | smalltext = }}

Note that when we have multiple classes, we also need to compute $\, log{|\Sigma_k|}$ respectively. Then we compute $\,\delta_k$ for QDA .

Note that when we have multiple classes, they must all have the same transformation, in another word, have same covariance $\,\Sigma_k$,else, ahead of time we would have to assume a data point belongs to one class or the other. All classes therefore need to have the same shape for classification to be applicable using this method. So this method works for LDA.

If the classes have different shapes, in another word, have different covariance $\,\Sigma_k$, can we use the same method to transform all data points $\,x$ to $\,x^*$?

The answer is NO. Consider that you have two classes with different shapes, then consider transforming them to the same shape. Given a data point, justify which class this point belongs to. The question is, which transformation can you use? For example, if you use the transformation of class A, then you have assumed that this data point belongs to class A.

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: The statement above may not be true, because in assignment 1, we did do the QDA computation using this approach although the corresponding three covarience matrices are different, the reason why the answer is Yes is as below. Please improve this article if you can. (October 18 2010) | small = | smallimage = | smallimageright = | smalltext = }}

The answer is Yes. Consider that you have two classes with different shapes. Given a data point, justify which class this point belongs to. You just do the transformations corresponding to the 2 classes respectively, then you get $\,\delta_1 ,\delta_2$ ,then you determine which class the data point belongs to by comparing $\,\delta_1$ and $\,\delta_2$ .

In summary, to apply QDA on a data set $\,X$, in the general case where $\, \Sigma_k \ne I$ for each class $\,k$, one can proceed as follows:

Step 1: For each class $\,k$, apply singular value decomposition on $\,X_k$ to obtain $\,S_k$ and $\,U_k$.
Step 2: For each class $\,k$, transform each $\,x$ belonging to that class to $\,x^* = S_k^{-\frac{1}{2}}U_k^\top x$, and transform its center $\,\mu_k$ to $\,\mu_k^* = S_k^{-\frac{1}{2}}U_k^\top \mu_k$.
Step 3: For each data point $\,x \in X$, find the squared Euclidean distance between the transformed data point $\,x^*$ and the transformed center $\,\mu^*$ of each class, and assign $\,x$ to the class such that the squared Euclidean distance between $\,x^*$ and $\,\mu^*$ is the least over all of the classes.

Now, let us consider LDA. Here, one can derive a classification scheme that is quite similar to that shown above. The main difference is the assumption of a common variance across the classes, so we perform the Singular Value Decomposition once, as opposed to k times.

To apply LDA on a data set $\,X$, one can proceed as follows:

Step 1: Apply singular value decomposition on $\,X$ to obtain $\,S$ and $\,U$.
Step 2: For each $\,x \in X$, transform $\,x$ to $\,x^* = S^{-\frac{1}{2}}U^\top x$, and transform each center $\,\mu$ to $\,\mu^* = S^{-\frac{1}{2}}U^\top \mu$.
Step 3: For each data point $\,x \in X$, find the squared Euclidean distance between the transformed data point $\,x^*$ and the transformed center $\,\mu^*$ of each class, and assign $\,x$ to the class such that the squared Euclidean distance between $\,x^*$ and $\,\mu^*$ is the least over all of the classes.

Kernel QDA In actual data scenarios, it is generally true that QDA will provide a better classifier for the data then LDA because QDA does not assume that the covariance matrix for each class is identical, as LDA assumes. However, QDA still assumes that the class conditional distribution is Gaussian, which is not always the case in real-life scenarios. The link provided at the beginning of this paragraph describes a kernel-based QDA method which does not have the Gaussian distribution assumption.

The Number of Parameters in LDA and QDA

Both LDA and QDA require us to estimate parameters. The more estimation we have to do, the less robust our classification algorithm will be.

LDA: Since we just need to compare the differences between one given class and remaining $\,K-1$ classes, totally, there are $\,K-1$ differences. For each of them, $\,a^{T}x+b$ requires $\,d+1$ parameters. Therefore, there are $\,(K-1)\times(d+1)$ parameters.

QDA: For each of the differences, $\,x^{T}ax + b^{T}x + c$ requires $\frac{1}{2}(d+1)\times d + d + 1 = \frac{d(d+3)}{2}+1$ parameters. Therefore, there are $(K-1)(\frac{d(d+3)}{2}+1)$ parameters.

A plot of the number of parameters that must be estimated, in terms of (K-1). The x-axis represents the number of dimensions in the data. As is easy to see, QDA is far less robust than LDA for high-dimensional data sets.

Trick: Using LDA to do QDA - September 28, 2010

There is a trick that allows us to use the linear discriminant analysis (LDA) algorithm to generate as its output a quadratic function that can be used to classify data. This trick is similar to, but more primitive than, the Kernel trick that will be discussed later in the course.

Essentially, the trick involves adding one or more new features (i.e. new dimensions) that just contain our original data projected to that dimension. We then do LDA on our new higher-dimensional data. The answer provided by LDA can then be collapsed onto a lower dimension, giving us a quadratic answer.

Motivation

Why would we want to use LDA over QDA? In situations where we have fewer data points, LDA turns out to be more robust.

If we look back at the equations for LDA and QDA, we see that in LDA we must estimate $\,\mu_1$, $\,\mu_2$ and $\,\Sigma$. In QDA we must estimate all of those, plus another $\,\Sigma$; the extra $\,\frac{d(d-1)}{2}$ estimations make QDA less robust with fewer data points.

Theoretically

Suppose we can estimate some vector $\underline{w}^T$ such that

$y = \underline{w}^Tx$

where $\underline{w}$ is a d-dimensional column vector, and $x\ \epsilon\ \mathbb{R}^d$ (vector in d dimensions).

We also have a non-linear function $g(x) = y = x^Tvx + \underline{w}^Tx$ that we cannot estimate.

Using our trick, we create two new vectors, $\,\underline{w}^*$ and $\,x^*$ such that:

$\underline{w}^{*T} = [w_1,w_2,...,w_d,v_1,v_2,...,v_d]$

and

$x^{*T} = [x_1,x_2,...,x_d,{x_1}^2,{x_2}^2,...,{x_d}^2]$

We can then estimate a new function, $g^*(x,x^2) = y^* = \underline{w}^{*T}x^*$.

Note that we can do this for any $x$ and in any dimension; we could extend a $D \times n$ matrix to a quadratic dimension by appending another $D \times n$ matrix with the original matrix squared, to a cubic dimension with the original matrix cubed, or even with a different function altogether, such as a $\,sin(x)$ dimension. Pay attention, We don't do QDA with LDA. If we try QDA directly on this problem the resulting decision boundary will be different. Here we try to find a nonlinear boundary for a better possible boundary but it is different with general QDA method. We can call it nonlinear LDA.

By Example

Let's use our trick to do a quadratic analysis of the 2_3 data using LDA.

>> load 2_3;
>> [U, sample] = princomp(X');
>> sample = sample(:,1:2);

We start off the same way, by using PCA to reduce the dimensionality of our data to 2.
>> X_star = zeros(400,4);
>> X_star(:,1:2) = sample(:,:);
>> for i=1:400
for j=1:2
X_star(i,j+2) = X_star(i,j)^2;
end
end

This projects our sample into two more dimensions by squaring our initial two dimensional data set.
>> group = ones(400,1);
>> group(201:400) = 2;
>> [class, error, POSTERIOR, logp, coeff] = classify(X_star, X_star, group, 'linear');
>> sum (class==group)
ans =
375

We can now display our results.
>> k = coeff(1,2).const;
>> l = coeff(1,2).linear;
>> f = sprintf('0 = %g+%g*x+%g*y+%g*(x)^2+%g*(y)^2', k, l(1), l(2),l(3),l(4));
>> ezplot(f,[min(sample(:,1)), max(sample(:,1)), min(sample(:,2)), max(sample(:,2))]);

The plot shows the quadratic decision boundary obtained using LDA in the four-dimensional space on the 2_3.mat data. Counting the blue and red points that are on the wrong side of the decision boundary, we can confirm that we have correctly classified 375 data points.
Not only does LDA give us a better result than it did previously, it actually beats QDA, which only correctly classified 371 data points for this data set. Continuing this procedure by adding another two dimensions with $x^4$ (i.e. we set X_star(i,j+2) = X_star(i,j)^4) we can correctly classify 376 points.

LDA and QDA in Matlab

We have examined the theory behind Linear Discriminant Analysis (LDA) and Quadratic Discriminant Analysis (QDA) above; how do we use these algorithms in practice? Matlab offers us a function called classify that allows us to perform LDA and QDA quickly and easily.

In class, we were shown an example of using LDA and QDA on the 2_3 data that is used in the first assignment. The code below applies LDA to the same data set and reproduces that example, slightly modified, and explains each step.

>> load 2_3;
>> [U, sample] = princomp(X');
>> sample = sample(:,1:2);

First, we do principal component analysis (PCA) on the 2_3 data to reduce the dimensionality of the original data from 64 dimensions to 2. Doing this makes it much easier to visualize the results of the LDA and QDA algorithms.

>> plot (sample(1:200,1), sample(1:200,2), '.');
>> hold on;
>> plot (sample(201:400,1), sample(201:400,2), 'r.');

Recall that in the 2_3 data, the first 200 elements are images of the number two handwritten and the last 200 elements are images of the number three handwritten. This code sets up a plot of the data such that the points that represent a 2 are blue, while the points that represent a 3 are red.
See title and legend for information on adding the title and legend.
Before using classify we can set up a vector that contains the actual labels for our data, to train the classification algorithm. If we don't know the labels for the data, then the element in the group vector should be an empty string or NaN. (See grouping data for more information.)
>> group = ones(400,1);
>> group(201:400) = 2;

We can now classify our data.
>> [class, error, POSTERIOR, logp, coeff] = classify(sample, sample, group, 'linear');

The full details of this line can be examined in the Matlab help file linked above. What we care about are class, which contains the labels that the algorithm thinks that each data point belongs to, and coeff, which contains information about the line that the algorithm created to separate the data into the two classes.
We can see the efficacy of the algorithm by comparing class to group.
>> sum (class==group)
ans =
369

This compares the value in class to the value in group. The answer of 369 tells us that the algorithm correctly determined the classes of the points 369 times, out of a possible 400 data points. This gives us an empirical error rate of 0.0775.
We can see the line produced by LDA using coeff.
>> k = coeff(1,2).const;
>> l = coeff(1,2).linear;
>> f = sprintf('0 = %g+%g*x+%g*y', k, l(1), l(2));
>> ezplot(f, [min(sample(:,1)), max(sample(:,1)), min(sample(:,2)), max(sample(:,2))]);

Those familiar with the programming language C will find the sprintf line refreshingly familiar; those with no exposure to C are directed to Matlab's sprintf page. Essentially, this code sets up the equation of the line in the form 0 = a + bx + cy. We then use the ezplot function to plot the line.
The 2-3 data after LDA is performed. The line shows where the two classes are split.
Let's perform the same steps, except this time using QDA. The main difference with QDA is a slightly different call to classify, and a more complicated procedure to plot the line.
>> [class, error, POSTERIOR, logp, coeff] = classify(sample, sample, group, 'quadratic');
>> sum (class==group)
ans =
371
>> k = coeff(1,2).const;
>> l = coeff(1,2).linear;
>> f = sprintf('0 = %g+%g*x+%g*y+%g*x^2+%g*x*y+%g*y^2', k, l(1), l(2), q(1,1), q(1,2)+q(2,1), q(2,2));
>> ezplot(f, [min(sample(:,1)), max(sample(:,1)), min(sample(:,2)), max(sample(:,2))]);

The 2-3 data after QDA is performed. The curved line shows where QDA splits the two classes. Note that QDA is only correct in 2 more data points compared to LDA; we can see a blue point and a red point that lie on the correct side of the curve produced by QDA that do not lie on the correct side of the line produced by LDA.

classify can also be used with other discriminant analysis algorithms. The steps laid out above would only need to be modified slightly for those algorithms.

Recall: An analysis of the function of princomp in matlab.
In our assignment 1, we have learnt that how to perform Principal Component Analysis using SVD method. In fact, the matlab offers us a function called princomp which can perform PCA conveniently. From the matlab help file on princomp, you can find the details about this function. But here we will analyze the code of the function of princomp() in matlab to find something different when comparing with SVD method. The following is the code of princomp and explanations to some emphasized steps.

   function [pc, score, latent, tsquare] = princomp(x);
%   PRINCOMP Principal Component Analysis (centered and scaled data).
%   [PC, SCORE, LATENT, TSQUARE] = PRINCOMP(X) takes a data matrix X and
%   returns the principal components in PC, the so-called Z-scores in SC
%   ORES, the eigenvalues of the covariance matrix of X in LATENT,
%   and Hotelling's T-squared statistic for each data point in TSQUARE.
%   Reference: J. Edward Jackson, A User's Guide to Principal Components
%   John Wiley & Sons, Inc. 1991 pp. 1-25.
%   B. Jones 3-17-94
%   Copyright 1993-2002 The MathWorks, Inc.
%   $Revision: 2.9$  $Date: 2002/01/17 21:31:45$
[m,n] = size(x);       %  get the lengh of the rows and columns of matrix x.
r = min(m-1,n);        %  max possible rank of X
avg = mean(x);         %  the mean of every column of X
centerx = (x - avg(ones(m,1),:));
%  centers X by subtracting off column means
[U,latent,pc] = svd(centerx./sqrt(m-1),0);
%  "economy size" decomposition
score = centerx*pc;
%  the representation of X in the principal component space
if nargout < 3
return;
end
latent = diag(latent).^2;
if (r   latent = [latent(1:r); zeros(n-r,1)];
score(:,r+1:end) = 0;
end
if nargout < 4
return;
end
tmp = sqrt(diag(1./latent(1:r)))*score(:,1:r)';
tsquare = sum(tmp.*tmp)';


From the above code, we should pay attention to the following aspects when comparing with SVD method:

First, Rows of $\,X$ correspond to observations, columns to variables. When using princomp on 2_3 data in assignment 1, note that we take the transpose of $\,X$.

 >> load 2_3;
>> [U, score] = princomp(X');


Second, princomp centers X by subtracting off column means.

The third, when $\,X=UdV'$, princomp uses $\,V$ as coefficients for principal components, rather than $\,U$.

The following is an example to perform PCA using princomp and SVD respectively to get the same results.

SVD method
 >> load 2_3
>> mn=mean(X,2);
>> X1=X-repmat(mn,1,400);
>> [s d v]=svd(X1');
>> y=X1'*v;

princomp
 >>[U score]=princomp(X');


Then we can see that y=score, v=U.

useful resouces: LDA and QDA in Matlab[6],[7],[8]

Reference

1. Harry Zhang. The optimality of naive bayes. FLAIRS Conference. AAAI Press, 2004

2. Rich Caruana and Alexandru N. Mizil. An empirical comparison of supervised learning algorithms. In ICML ’06: Proceedings of the 23rd international conference on Machine learning, pages 161–168, New York, NY, USA, 2006, ACM.

LDA:[9]

QDA:[11]

Principal Component Analysis - September 30, 2010

Rough definition

Keepings two important aspects of data analysis in mind:

• Reducing covariance in data
• Preserving information stored in data(Variance is a source of information)

Principal component analysis (PCA) is a dimensionality-reduction method invented by Karl Pearson in 1901 [12]. Depending on where this methodology is applied, other common names of PCA include the Karhunen–Loève transform (KLT) , the Hotelling transform, and the proper orthogonal decomposition (POD). PCA is the simplist eigenvector-based multivariate analysis. It reduces the dimensionality of the data by revealing the internal structure of the data in a way that best explains the variance in the data. To this end, PCA works by using a user-defined number of the most important directions of variation (dimensions or principal components) of the data to project the data onto these directions so as to produce a lower-dimensional representation of the original data. The resulting lower-dimensional representation of our data is usually much easier to visualize and it also exhibits the most informative aspects (dimensions) of our data whilst capturing as much of the variation exhibited by our data as it possibly could.

Furthermore, if one considers the lower dimensional representation produced by PCA as a least squares fit of our original data, then it can also be easily shown that this representation is the one that minimizes the reconstruction error of our data. It should be noted however, that one usually does not have control over which dimensions PCA deems to be the most informative for a given set of data, and thus one usually does not know which dimensions PCA selects to be the most informative dimensions in order to create the lower-dimensional representation.

Suppose $\,X$ is our data matrix containing $\,d$-dimensional data. The idea behind PCA is to apply singular value decomposition to $\,X$ to replace the rows of $\,X$ by a subset of it that captures as much of the variance in $\,X$ as possible. First, through the application of singular value decomposition to $\,X$, PCA obtains all of our data's directions of variation. These directions would also be ordered from left to right, with the leftmost directions capturing the most amount of variation in our data and the rightmost directions capturing the least amount. Then, PCA uses a subset of these directions to map our data from its original space to a lower-dimensional space.

By applying singular value decomposition to $\,X$, $\,X$ is decomposed as $\,X = U\Sigma V^T \,$. The $\,d$ columns of $\,U$ are the eigenvectors of $\,XX^T \,$. The $\,d$ columns of $\,V$ are the eigenvectors of $\,X^TX \,$. The $\,d$ diagonal values of $\,\Sigma$ are the square roots of the eigenvalues of $\,XX^T \,$ (also of $\,X^TX \,$), and they correspond to the columns of $\,U$ (also of $\,V$).

We are interested in $\,U$, whose $\,d$ columns are the $\,d$ directions of variation of our data. Ordered from left to right, the $\,ith$ column of $\,U$ is the $\,ith$ most informative direction of variation of our data. That is, the $\,ith$ column of $\,U$ is the $\,ith$ most effective column in terms of capturing the total variance exhibited by our data. A subset of the columns of $\,U$ is used by PCA to reduce the dimensionality of $\,X$ by projecting $\,X$ onto the columns of this subset. In practice, when we apply PCA to $\,X$ to reduce the dimensionality of $\,X$ from $\,d$ to $\,k$, where $k \lt d\,$, we would proceed as follows:

Step 1: Center $\,X$ so that it would have zero mean.
Step 2: Apply singular value decomposition to $\,X$ to obtain $\,U$.
Step 3: Suppose we denote the resulting $\,k$-dimensional representation of $\,X$ by $\,Y$. Then, $\,Y$ is obtained as $\,Y = U_k^TX$. Here, $\,U_k$ consists of the first (leftmost) $\,k$ columns of $\,U$ that correspond to the $\,k$ largest diagonal elements of $\,\Sigma$.

PCA takes a sample of d - dimensional vectors and produces an orthogonal(zero covariance) set of d 'Principal Components'. The first Principal Component is the direction of greatest variance in the sample. The second principal component is the direction of second greatest variance (orthogonal to the first component), etc.

Then we can preserve most of the variance in the sample in a lower dimension by choosing the first k Principle Components and approximating the data in k - dimensional space, which is easier to analyze and plot.

Principal Components of handwritten digits

Suppose that we have a set of 130 images (28 by 23 pixels) of handwritten threes. {{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: If anyone can tell me where I can find the 2-3 data set, I would create the new image. In the mean time, I found a non-copyrighted image of different looking 3s online, but as you can see, it is not as nice as one we could make.. Please improve this article if you can. (September 6 2010) | small = | smallimage = | smallimageright = | smalltext = }} {{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: I think you can find it on your UW-ACE account for this course.. Please improve this article if you can. (September 6 2010) | small = | smallimage = | smallimageright = | smalltext = }}

We can represent each image as a vector of length 644 ($644 = 23 \times 28$). Then we can represent the entire data set as a 644 by 130 matrix, shown below. Each column represents one image (644 rows = 644 pixels).

Using PCA, we can approximate the data as the product of two smaller matrices, which I will call $V \in M_{644,2}$ and $W \in M_{2,103}$. If we expand the matrix product then each image is approximated by a linear combination of the columns of V: $\hat{f}(\lambda) = \bar{x} + \lambda_1 v_1 + \lambda_2 v_2$, where $\lambda = [\lambda_1, \lambda_2]^T$ is a column of W.

To demonstrate this process, we can compare the images of 2s and 3s. We will apply PCA to the data, and compare the images of the labeled data. This is an example in classifying.

Don't worry about the constant term for now. The point is that we can represent an image using just 2 coefficients instead of 644. Also notice that the coefficients correspond to features of the handwritten digits. The picture below shows the first two principal components for the set of handwritten threes.

The first coefficient represents the width of the entire digit, and the second coefficient represents the slant of each handwritten digit.

Derivation of the first Principle Component

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: I think English of this section must be improved. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }} We want to find the direction of maximum variation. Let \begin{align}\textbf{w}\end{align} be an arbitrary direction, \begin{align}\textbf{x}\end{align} a data point and \begin{align}\displaystyle u\end{align} the length of the projection of \begin{align}\textbf{x}\end{align} in direction \begin{align}\textbf{w}\end{align}.

\begin{align} \textbf{w} &= [w_1, \ldots, w_D]^T \\ \textbf{x} &= [x_1, \ldots, x_D]^T \\ u &= \frac{\textbf{w}^T \textbf{x}}{\sqrt{\textbf{w}^T\textbf{w}}} \end{align}

The direction \begin{align}\textbf{w}\end{align} is the same as \begin{align}c\textbf{w}\end{align}, for any scalar $c$, so without loss of generality, we assume that:

\begin{align} |\textbf{w}| &= \sqrt{\textbf{w}^T\textbf{w}} = 1 \\ u &= \textbf{w}^T \textbf{x}. \end{align}

Let $x_1, \ldots, x_D$ be random variables, then our goal is to maximize the variance of $u$,

$\textrm{var}(u) = \textrm{var}(\textbf{w}^T \textbf{x}) = \textbf{w}^T \Sigma \textbf{w}.$

For a finite data set we replace the covariance matrix $\Sigma$ by $s$, the sample covariance matrix

$\textrm{var}(u) = \textbf{w}^T s\textbf{w} .$

The above is the variance of \begin{align}\displaystyle u \end{align} formed by the weight vector \begin{align}\textbf{w} \end{align}. The first principal component is the vector \begin{align}\textbf{w} \end{align} that maximizes the variance,

$\textrm{PC} = \underset{\textbf{w}}{\operatorname{arg\,max}} \, \left( \operatorname{var}(u) \right) = \underset{\textbf{w}}{\operatorname{arg\,max}} \, \left( \textbf{w}^T s \textbf{w} \right)$

where arg max denotes the value of \begin{align}\textbf{w} \end{align} that maximizes the function. Our goal is to find the weight \begin{align}\textbf{w} \end{align} that maximizes this variability, subject to a constraint. Since our function is convex, it has no maximum value. Therefore we need to add a constraint that restricts the length of \begin{align}\textbf{w} \end{align}. However, we are only interested in the direction of the variability, so the problem becomes

$\underset{\textbf{w}}{\operatorname{max}} \, \left( \textbf{w}^T s \textbf{w} \right)$

s.t. $\textbf{w}^T \textbf{w} = 1.$

Notice,

$\textbf{w}^T s \textbf{w} \leq \| \textbf{w}^T s \textbf{w} \| \leq \| s \| \| \textbf{w} \| = \| s \|.$

Therefore the variance is bounded, so the maximum exists. We find the this maximum using the method of Lagrange multipliers.

Lagrange Multiplier

Before we can proceed, we must review Lagrange Multipliers.

"The red line shows the constraint g(x,y) = c. The blue lines are contours of f(x,y). The point where the red line tangentially touches a blue contour is our solution." [Lagrange Multipliers, Wikipedia]

To find the maximum (or minimum) of a function $\displaystyle f(x,y)$ subject to constraints $\displaystyle g(x,y) = 0$, we define a new variable $\displaystyle \lambda$ called a Lagrange Multiplier and we form the Lagrangian,

$\displaystyle L(x,y,\lambda) = f(x,y) - \lambda g(x,y)$

If $\displaystyle (x^*,y^*)$ is the max of $\displaystyle f(x,y)$, there exists $\displaystyle \lambda^*$ such that $\displaystyle (x^*,y^*,\lambda^*)$ is a stationary point of $\displaystyle L$ (partial derivatives are 0).
In addition $\displaystyle (x^*,y^*)$ is a point in which functions $\displaystyle f$ and $\displaystyle g$ touch but do not cross. At this point, the tangents of $\displaystyle f$ and $\displaystyle g$ are parallel or gradients of $\displaystyle f$ and $\displaystyle g$ are parallel, such that:

$\displaystyle \nabla_{x,y } f = \lambda \nabla_{x,y } g$

where,
$\displaystyle \nabla_{x,y} f = (\frac{\partial f}{\partial x},\frac{\partial f}{\partial{y}}) \leftarrow$ the gradient of $\, f$
$\displaystyle \nabla_{x,y} g = (\frac{\partial g}{\partial{x}},\frac{\partial{g}}{\partial{y}}) \leftarrow$ the gradient of $\, g$

Example

Suppose we wish to maximise the function $\displaystyle f(x,y)=x-y$ subject to the constraint $\displaystyle x^{2}+y^{2}=1$. We can apply the Lagrange multiplier method on this example; the lagrangian is:

$\displaystyle L(x,y,\lambda) = x-y - \lambda (x^{2}+y^{2}-1)$

We want the partial derivatives equal to zero:

$\displaystyle \frac{\partial L}{\partial x}=1+2 \lambda x=0$

$\displaystyle \frac{\partial L}{\partial y}=-1+2\lambda y=0$

$\displaystyle \frac{\partial L}{\partial \lambda}=x^2+y^2-1$

Solving the system we obtain 2 stationary points: $\displaystyle (\sqrt{2}/2,-\sqrt{2}/2)$ and $\displaystyle (-\sqrt{2}/2,\sqrt{2}/2)$. In order to understand which one is the maximum, we just need to substitute it in $\displaystyle f(x,y)$ and see which one as the biggest value. In this case the maximum is $\displaystyle (\sqrt{2}/2,-\sqrt{2}/2)$.

Determining W

Back to the original problem, from the Lagrangian we obtain,

$\displaystyle L(\textbf{w},\lambda) = \textbf{w}^T S \textbf{w} - \lambda (\textbf{w}^T \textbf{w} - 1)$

If $\textbf{w}^T \textbf{w}$ is a unit vector then the second part of the equation is 0.

If $\textbf{w}^T \textbf{w}$ is not a unit vector then the second part of the equation increases. Thus decreasing overall $\displaystyle L(\textbf{w},\lambda)$. Maximization happens when $\textbf{w}^T \textbf{w} =1$

(Note that to take the derivative with respect to w below, $\textbf{w}^T S \textbf{w}$ can be thought of as a quadratic function of w, hence the 2sw below. For more matrix derivatives, see section 2 of the Matrix Cookbook)

Taking the derivative with respect to w, we get:

$\displaystyle \frac{\partial L}{\partial \textbf{w}} = 2S\textbf{w} - 2\lambda\textbf{w}$

Set $\displaystyle \frac{\partial L}{\partial \textbf{w}} = 0$, we get

$\displaystyle S\textbf{w}^* = \lambda^*\textbf{w}^*$

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: It is good discussion, what will happen if we don't have distinct eigenvalues and eigenvectors? What does this situation mean?. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }} {{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: If the eigenvalues are not distinct, I suppose we could still take the leftmost eigenvector by default. Not sure if this is the correct approach, so can anyone please explain further? Thanks. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }} {{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: As U is the eigenvector of a symetric matrix, is it possible that we have 2 similar eigen vector?. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }}

From the eigenvalue equation $\, \textbf{w}^*$ is an eigenvector of S and $\, \lambda^*$ is the corresponding eigenvalue of S. If we substitute $\displaystyle\textbf{w}^*$ in $\displaystyle \textbf{w}^T S\textbf{w}$ we obtain,

$\displaystyle\textbf{w}^{*T} S\textbf{w}^* = \textbf{w}^{*T} \lambda^* \textbf{w}^* = \lambda^* \textbf{w}^{*T} \textbf{w}^* = \lambda^*$

In order to maximize the objective function we choose the eigenvector corresponding to the largest eigenvalue. We choose the first PC, u1 to have the maximum variance
(i.e. capturing as much variability in $\displaystyle x_1, x_2,...,x_D$ as possible.) Subsequent principal components will take up successively smaller parts of the total variability.

D dimensional data will have D eigenvectors

$\lambda_1 \geq \lambda_2 \geq ... \geq \lambda_D$ where each $\, \lambda_i$ represents the amount of variation in direction $\, i$

so that

$Var(u_1) \geq Var(u_2) \geq ... \geq Var(u_D)$

Note that the Principal Components decompose the total variance in the data:

$\displaystyle \sum_{i = 1}^D Var(u_i) = \sum_{i = 1}^D \lambda_i = Tr(S) = Var(\sum_{i = 1}^n x_i)$

i.e. the sum of variations in all directions is the variation in the whole data

Example from class

We apply PCA to the noise data, making the assumption that the intrinsic dimensionality of the data is 10. We now try to compute the reconstructed images using the top 10 eigenvectors and plot the original and reconstructed images

The Matlab code is as follows:

 load noisy
who
size(X)
imagesc(reshape(X(:,1),20,28)')
colormap gray
imagesc(reshape(X(:,1),20,28)')
m_X=mean(X,2);
mm=repmat(m_X,1,300);
XX=X-mm;
[u s v] = svd(XX);
xHat = u(:,1:10)*s(1:10,1:10)*v(:,1:10)'; % use ten principal components
xHat=xHat+mm;
figure
imagesc(reshape(xHat(:,1000),20,28)') % here '1000' can be changed to different values, e.g. 105, 500, etc.
colormap gray


Running the above code gives us 2 images - the first one represents the noisy data - we can barely make out the face

The second one is the denoised image

As you can clearly see, more features can be distinguished from the picture of the de-noised face compared to the picture of the noisy face. This is because almost all of the noise in the noisy image is captured by the principal components (directions of variation) that capture the least amount of variation in the image, and these principal components were discarded when we used the few principal components that capture most of the image's variation to generate the image's lower-dimensional representation. If we took more principal components, at first the image would improve since the intrinsic dimensionality is probably more than 10. But if you include all the components you get the noisy image, so not all of the principal components improve the image. In general, it is difficult to choose the optimal number of components.

Application of PCA - Feature Extraction

One of the applications of PCA is to group similar data (e.g. images). There are generally two methods to do this. We can classify the data (i.e. give each data a label and compare different types of data) or cluster (i.e. do not label the data and compare output for classes).

Generally speaking, we can do this with the entire data set (if we have an 8X8 picture, we can use all 64 pixels). However, this is hard, and it is easier to use the reduced data and features of the data.

General PCA Algorithm

The PCA Algorithm is summarized as follows (taken from the Lecture Slides).

Algorithm

Recover basis: Calculate $XX^T =\Sigma_{i=1}^{n} x_i x_{i}^{T}$ and let $U=$ eigenvectors of $X X^T$ corresponding to the top $d$ eigenvalues.

Encoding training data: Let $Y=U^TX$ where $Y$ is a $d \times n$ matrix of encoding of the original data.

Reconstructing training data: $\hat{X}= UY=UU^TX$.

Encode set example: $y=U^T x$ where $y$ is a $d-$dimentional encoding of $x$.

Reconstruct test example: $\hat{x}= Uy=UU^Tx$.

Other Notes:

1. The mean of the data(X) must be 0. This means we may have to preprocess the data by subtracting off the mean(see detailsPCA in Wikipedia.)
2. Encoding the data means that we are projecting the data onto a lower dimensional subspace by taking the inner product. Encoding: $X_{D\times n} \longrightarrow Y_{d\times n}$ using mapping $\, U^T X_{D \times n}$.
3. When we reconstruct the training set, we are only using the top d dimensions.This will eliminate the dimensions that have lower variance (e.g. noise). Reconstructing: $\hat{X}_{D\times n}\longleftarrow Y_{d \times n}$ using mapping $\, U_dY_{d \times n}$, where $\,U_d$ contains the first (leftmost) $\,d$ columns of $\,U$.
4. We can compare the reconstructed test sample to the reconstructed training sample to classify the new data.

Fisher's (Linear) Discriminant Analysis (FDA) - Two Class Problem - October 5, 2010

Sir Ronald A. Fisher

Fisher's Discriminant Analysis (FDA), also known as Fisher's Linear Discriminant Analysis (LDA) in some sources, is a classical feature extraction technique. It was originally described in 1936 by Sir Ronald Aylmer Fisher, an English statistician and eugenicist who has been described as one of the founders of modern statistical science. His original paper describing FDA can be found here; a Wikipedia article summarizing the algorithm can be found here. In this paper Fisher used for the first time the term DISCRIMINANT FUNCTION. The term DISCRIMINANT ANALYSIS was introduced later by Fisher himself in a subsequent paper which can be found here.

Contrasting FDA with PCA

As in PCA, the goal of FDA is to project the data in a lower dimension. You might ask, why was FDA invented when PCA already existed? There is a simple explanation for this that can be found here. PCA is an unsupervised method for classification, so it does not take into account the labels in the data. Suppose we have two clusters that have very different or even opposite labels from each other but are nevertheless positioned in a way such that they are very much parallel to each other and also very near to each other. In this case, most of the total variation of the data is in the direction of these two clusters. If we use PCA in cases like this, then both clusters would be projected onto the direction of greatest variation of the data to become sort of like a single cluster after projection. PCA would therefore mix up these two clusters that, in fact, have very different labels. What we need to do instead, in this cases like this, is to project the data onto a direction that is orthogonal to the direction of greatest variation of the data. This direction is in the least variation of the data. On the 1-dimensional space resulting from such a projection, we would then be able to effectively classify the data, because these two clusters would be perfectly or nearly perfectly separated from each other taking into account of their labels. This is exactly the idea behind FDA.

The main difference between FDA and PCA is that, in FDA, in contrast to PCA, we are not interested in retaining as much of the variance of our original data as possible. Rather, in FDA, our goal is to find a direction that is useful for classifying the data (i.e. in this case, we are looking for a direction that is most representative of a particular characteristic e.g. glasses vs. no-glasses). Suppose we have 2-dimensional data, then FDA would attempt to project the data of each class onto a point in such a way that the resulting two points would be as far apart from each other as possible. Intuitively, this basic idea behind FDA is the optimal way for separating each pair of classes along a certain direction.

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: Just a thought: how relevant is "Dimensionality reduction techniques" to the concept of "subspace clustering"? As in subspace clustering, the goal is to find a set of features (relevant features, the concept is referred to as local feature relevance in the literature) in the high dimensional space, where potential subspaces accommodating different classes of data points can be defined. This means; the data points are dense when they are considered in a subset of dimensions (features).. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }} {{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: If I'm not mistaken, classification techniques like FDA use labeled training data whereas clustering techniques use unlabeled training data instead. Any other input regarding this would be much appreciated. Thanks. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }} {{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: An extension of clustering is subspace clustering in which different subspace are searched through to find the relavant and appropriate dimentions. High dimentional data sets are roughly equiedistant from each other, so feature selection methods are used to remove the irrelavant dimentions. These techniques do not keep the relative distance so PCA is not useful for these applications. It should be noted that subspace clustering localize their search unlike feature selection algorithms.for more information click here[13]. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }}

The number of dimensions that we want to reduce the data to depends on the number of classes:
For a 2-classes problem, we want to reduce the data to one dimension (a line), $\displaystyle Z \in \mathbb{R}^{1}$
Generally, for a k-classes problem, we want to reduce the data to k-1 dimensions, $\displaystyle Z \in \mathbb{R}^{k-1}$

As we will see from our objective function, we want to maximize the separation of the classes and to minimize the within-variance of each class. That is, our ideal situation is that the individual classes are as far away from each other as possible, and at the same time the data within each class are as close to each other as possible (collapsed to a single point in the most extreme case).

The following diagram summarizes this goal.

In fact, the two examples above may represent the same data projected on two different lines.

Distance Metric Learning VS FDA

In many fundamental machine learning problems, the Euclidean distances between data points do not represent the desired topology that we are trying to capture. Kernel methods address this problem by mapping the points into new spaces where Euclidean distances may be more useful. An alternative approach is to construct a Mahalanobis distance (quadratic Gaussian metric) over the input space and use it in place of Euclidean distances. This approach can be equivalently interpreted as a linear transformation of the original inputs, followed by Euclidean distance in the projected space. This approach has attracted a lot of recent interest.

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: Anyone please add an example to make the comparison clearer. Please improve this article if you can. (October2010) | small = | smallimage = | smallimageright = | smalltext = }}

Some of the proposed algorithms are iterative and computationally expensive. In the paper,"Distance Metric Learning VS FDA " written by our instructor, they propose a closed-form solution to one algorithm that previously required expensive semidefinite optimization. They provide a new problem setup in which the algorithm performs better or as well as some standard methods, but without the computational complexity. Furthermore, they show a strong relationship between these methods and the Fisher Discriminant Analysis (FDA). They also extend the approach by kernelizing it, allowing for non-linear transformations of the metric.

FDA Goals

An intuitive description of FDA can be given by visualizing two clouds of data, as shown above. Ideally, we would like to collapse all of the data points in each cloud onto one point on some projected line, then make those two points as far apart as possible. In doing so, we make it very easy to tell which class a data point belongs to. In practice, it is not possible to collapse all of the points in a cloud to one point, but we attempt to make all of the points in a cloud close to each other while simultaneously far from the points in the other cloud.

Example in R

PCA and FDA primary dimension for normal multivariate data, using R.
>> X = matrix(nrow=400,ncol=2)
>> X[1:200,] = mvrnorm(n=200,mu=c(1,1),Sigma=matrix(c(1,1.5,1.5,3),2))
>> X[201:400,] = mvrnorm(n=200,mu=c(5,3),Sigma=matrix(c(1,1.5,1.5,3),2))
>> Y = c(rep("red",200),rep("blue",200))

Create 2 multivariate normal random variables with $\, \mu_1 = \left( \begin{array}{c}1 \\ 1 \end{array} \right), \mu_2 = \left( \begin{array}{c}5 \\ 3 \end{array} \right). ~\textrm{Cov} = \left( \begin{array}{cc} 1 & 1.5 \\ 1.5 & 3 \end{array} \right)$. Create Y, an index indicating which class they belong to.
>> s <- svd(X,nu=1,nv=1)

Calculate the singular value decomposition of X. The most significant direction is in s$v[,1], and is displayed as a black line. >> s2 <- lda(X,grouping=Y)  The lda function, given the group for each item, uses Fischer's Linear Discriminant Analysis (FLDA) to find the most discriminant direction. This can be found in s2$scaling.

Now that we've calculated the PCA and FLDA decompositions, we create a plot to demonstrate the differences between the two algorithms. FLDA is clearly better suited to discriminating between two classes whereas PCA is primarily good for reducing the number of dimensions when data is high-dimensional.

>> plot(X,col=Y,main="PCA vs. FDA example")

Plot the set of points, according to colours given in Y.
>> slope = s$v[2]/s$v[1]
>> intercept = mean(X[,2])-slope*mean(X[,1])
>> abline(a=intercept,b=slope)

Plot the main PCA direction, drawn through the mean of the dataset. Only the direction is significant.
>> slope2 = s2$scaling[2]/s2$scaling[1]
>> intercept2 = mean(X[,2])-slope2*mean(X[,1])
>> abline(a=intercept2,b=slope2,col="red")

Plot the FLDA direction, again through the mean.
>> legend(-2,7,legend=c("PCA","FDA"),col=c("black","red"),lty=1)

Labeling the lines directly on the graph makes it easier to interpret.

FDA projects the data into lower dimensional space, where the distances between the projected means are maximum and the within-class variances are minimum. There are two categories of classification problems:

1. Two-class problem

2. Multi-class problem (addressed next lecture)

Two-class problem

In the two-class problem, we have the pre-knowledge that data points belong to two classes. Intuitively speaking points of each class form a cloud around the mean of the class, with each class having possibly different size. To be able to separate the two classes we must determine the class whose mean is closest to a given point while also accounting for the different size of each class, which is represented by the covariance of each class.

Assume $\underline{\mu_{1}}=\frac{1}{n_{1}}\displaystyle\sum_{i:y_{i}=1}\underline{x_{i}}$ and $\displaystyle\Sigma_{1}$, represent the mean and covariance of the 1st class, and $\underline{\mu_{2}}=\frac{1}{n_{2}}\displaystyle\sum_{i:y_{i}=2}\underline{x_{i}}$ and $\displaystyle\Sigma_{2}$ represent the mean and covariance of the 2nd class. We have to find a transformation which satisfies the following goals:

1.To make the means of these two classes as far apart as possible

In other words, the goal is to maximize the distance after projection between class 1 and class 2. This can be done by maximizing the distance between the means of the classes after projection. When projecting the data points to a one-dimensional space, all points will be projected to a single line; the line we seek is the one with the direction that achieves maximum separation of classes upon projection. If the original points are $\underline{x_{i}} \in \mathbb{R}^{d}$and the projected points are $\underline{w}^T \underline{x_{i}}$ then the mean of the projected points will be $\underline{w}^T \underline{\mu_{1}}$ and $\underline{w}^T \underline{\mu_{2}}$ for class 1 and class 2 respectively. The goal now becomes to maximize the Euclidean distance between projected means, $(\underline{w}^T\underline{\mu_{1}}-\underline{w}^T\underline{\mu_{2}})^T (\underline{w}^T\underline{\mu_{1}}-\underline{w}^T\underline{\mu_{2}})$. The steps of this maximization are given below.

2.We want to collapse all data points of each class to a single point, i.e., minimize the covariance within each class

Notice that the variance of the projected classes 1 and 2 are given by $\underline{w}^T\Sigma_{1}\underline{w}$ and $\underline{w}^T\Sigma_{2}\underline{w}$. The second goal is to minimize the sum of these two covariances (the summation of the two covariances is a valid covariance, satisfying the symmetry and positive semi-definite criteria).

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: In 2. above, I wonder if the computation would be much more complex if we instead find a weighted sum of the covariances of the two classes where the weights are the sizes of the two classes?. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }}

As is demonstrated below, both of these goals can be accomplished simultaneously.

Original points are $\underline{x_{i}} \in \mathbb{R}^{d}$
$\ \{ \underline x_1 \underline x_2 \cdot \cdot \cdot \underline x_n \}$

Projected points are $\underline{z_{i}} \in \mathbb{R}^{1}$ with $\underline{z_{i}} = \underline{w}^T \cdot\underline{x_{i}}$ where $\ z_i$ is a scalar

1. Minimizing within-class variance

$\displaystyle \min_w (\underline{w}^T\sum_1\underline{w})$

$\displaystyle \min_w (\underline{w}^T\sum_2\underline{w})$

and this problem reduces to $\displaystyle \min_w (\underline{w}^T(\sum_1 + \sum_2)\underline{w})$
(where $\,\sum_1$ and $\,\sum_2$ are the covariance matrices of the 1st and 2nd classes of data, respectively)

Let $\displaystyle \ s_w=\sum_1 + \sum_2$ be the within-classes covariance. Then, this problem can be rewritten as $\displaystyle \min_w (\underline{w}^Ts_w\underline{w})$.

2. Maximize the distance between the means of the projected data

$\displaystyle \max_w ||\underline{w}^T \mu_1 - \underline{w}^T \mu_2||^2,$

\begin{align} ||\underline{w}^T \mu_1 - \underline{w}^T \mu_2||^2 &= (\underline{w}^T \mu_1 - \underline{w}^T \mu_2)^T(\underline{w}^T \mu_1 - \underline{w}^T \mu_2)\\ &= (\mu_1^T\underline{w} - \mu_2^T\underline{w})(\underline{w}^T \mu_1 - \underline{w}^T \mu_2)\\ &= (\mu_1 - \mu_2)^T \underline{w} \underline{w}^T (\mu_1 - \mu_2) \\ &= ((\mu_1 - \mu_2)^T \underline{w})^{T} (\underline{w}^T (\mu_1 - \mu_2))^{T} \\ &= \underline{w}^T(\mu_1 - \mu_2)(\mu_1 - \mu_2)^T \underline{w} \end{align}

Note that in the last line above the order is rearranged clockwise because the answer is a scalar.

Let $\displaystyle s_B = (\mu_1 - \mu_2)(\mu_1 - \mu_2)^T$, the between-class covariance, then the goal is to $\displaystyle \max_w (\underline{w}^T(\mu_1 - \mu_2)(\mu_1 - \mu_2)^T\underline{w})$ or $\displaystyle \max_w (\underline{w}^Ts_B\underline{w})$.

The Objective Function for FDA

We want an objective function which satisfies both of the goals outlined above (at the same time).

1. $\displaystyle \min_w (\underline{w}^T(\sum_1 + \sum_2)\underline{w})$ or $\displaystyle \min_w (\underline{w}^Ts_w\underline{w})$
2. $\displaystyle \max_w (\underline{w}^T(\mu_1 - \mu_2)(\mu_1 - \mu_2)^T\underline{w})$ or $\displaystyle \max_w (\underline{w}^Ts_B\underline{w})$

So, we construct our objective function as maximizing the ratio of the two goals brought above:

$\displaystyle \max_w \frac{(\underline{w}^T(\mu_1 - \mu_2)(\mu_1 - \mu_2)^T\underline{w})} {(\underline{w}^T(\sum_1 + \sum_2)\underline{w})}$

or equivalently,

$\displaystyle \max_w \frac{(\underline{w}^Ts_B\underline{w})}{(\underline{w}^Ts_w\underline{w})}$
One may argue that we can use subtraction for this purpose, while this approach is true but it can be shown it will need another scaling factor. Thus using this ratio is more efficient.

As the objective function is convex, and so it does not have a maximum. To get around this problem, we have to add the constraint that w must have unit length, and then solvethis optimization problem we form the lagrangian:

$\displaystyle L(\underline{w},\lambda) = \underline{w}^Ts_B\underline{w} - \lambda (\underline{w}^Ts_w\underline{w} -1)$

Then, we equate the partial derivative of L with respect to $\underline{w}$: $\displaystyle \frac{\partial L}{\partial \underline{w}}=2s_B \underline{w} - 2\lambda s_w \underline{w} = 0$

$s_B \underline{w} = \lambda s_w \underline{w}$
$s_w^{-1}s_B \underline{w}= \lambda\underline{w}$

This is in the form of generalized eigenvalue problem. Therefore, $\underline{w}$ is the largest eigenvector of $s_w^{-1}s_B$

This solution can be further simplified as follow:

$s_w^{-1}(\mu_1 - \mu_2)(\mu_1 - \mu_2)^T\underline{w} = \lambda\underline{w}$

Since $(\mu_1 - \mu_2)^T\underline{w}$ is a scalar then $s_w^{-1}(\mu_1 - \mu_2)$$\underline{w}$

This gives the direction of $\underline{w}$ without doing eigenvalue decomposition in the case of 2-class problem.

Note: In order for ${s_w}$ to have an inverse, it must have full rank. This can be achieved by ensuring that the number of data points $\,\ge$ the dimensionality of $\underline{x_{i}}$.

FDA Using Matlab

Note: The following example was not actually mentioned in this lecture

We see now an application of the theory that we just introduced. Using Matlab, we find the principal components and the projection by Fisher Discriminant Analysis of two Bivariate normal distributions to show the difference between the two methods.

      %First of all, we generate the two data set:
% First data set X1
X1 = mvnrnd([1,1],[1 1.5; 1.5 3], 300);
%In this case:
mu_1=[1;1];
Sigma_1=[1 1.5; 1.5 3];
%where mu and sigma are the mean and covariance matrix.
% Second data set X2
X2 = mvnrnd([5,3],[1 1.5; 1.5 3], 300);
%Here mu_2=[5;3] and Sigma_2=[1 1.5; 1.5 3]
%The plot of the two distributions is:
plot(X1(:,1),X1(:,2),'.b'); hold on;
plot(X2(:,1),X2(:,2),'ob')



      %We compute the principal components:
% Combine data sets to map both into the same subspace
X=[X1;X2];
X=X';
% We used built-in PCA function in Matlab
[coefs, scores]=princomp(X);

plot([0 coefs(1,1)], [0 coefs(2,1)],'b')
plot([0 coefs(1,1)]*10, [0 coefs(2,1)]*10,'r')
sw=2*[1 1.5;1.5 3]   % sw=Sigma1+Sigma2=2*Sigma1
w=sw\[4; 2]       % calculate s_w^{-1}(mu2 - mu1)
plot ([0 w(1)], [0 w(2)],'g')


      %We now make the projection:
Xf=w'*X
figure
plot(Xf(1:300),1,'ob') %In this case, since it's a one dimension data, the plot is "Data Vs Indexes"
hold on
plot(Xf(301:600),1,'or')



      %We see that in the above picture that there is very little overlapping
Xp=coefs(:,1)'*X
figure
plot(Xp(1:300),1,'b')
hold on
plot(Xp(301:600),2,'or')



      %In this case there is an overlapping since we project the first principal component on [Xp=coefs(:,1)'*X]


Some of FDA applications

There are many applications for FDA in many domains some of them are stated below:

• SPEECH/MUSIC/NOISE CLASSIFICATION IN HEARING AIDS

FDA can be used to enhance listening comprehension when the user goes from a sound environment to another different one. For more information review this paper by Alexandre et al.here

• Application to Face Recognition

FDA can be used in face recognition at different situation. Using FDA Kong et al. proposes an Application to Face Recognition with Small Number of Training Samples here.

• Palmprint Recognition

FDA is used in biometrics, to implement an automated palmprint recognition system. See An Automated Palmprint Recognition System by Tee et al. here.

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: I think briefing about the other applications would be easier than browsing through all of these applications. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }}

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: This link is no longer valid.. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }}

other applications could found in references 4,5,6,7,8 and more in here

References

1. Kong, H.; Wang, L.; Teoh, E.K.; Wang, J.-G.; Venkateswarlu, R.; , "A framework of 2D Fisher discriminant analysis: application to face recognition with small number of training samples," Computer Vision and Pattern Recognition, 2005. CVPR 2005. IEEE Computer Society Conference on , vol.2, no., pp. 1083- 1088 vol. 2, 20-25 June 2005 doi: 10.1109/CVPR.2005.30 1

2. Enrique Alexandre, Roberto Gil-Pita, Lucas Cuadra, Lorena A´lvarez, Manuel Rosa-Zurera, "SPEECH/MUSIC/NOISE CLASSIFICATION IN HEARING AIDS USING A TWO-LAYER CLASSIFICATION SYSTEM WITH MSE LINEAR DISCRIMINANTS", 16th European Signal Processing Conference (EUSIPCO 2008), Lausanne, Switzerland, August 25-29, 2008, copyright by EURASIP, 2

3. Connie, Tee; Jin, Andrew Teoh Beng; Ong, Michael Goh Kah; Ling, David Ngo Chek; "An automated palmprint recognition system", Journal of Image and Vision Computing, 2005. 3

4. met, Francesca; Boqué, Ricard; Ferré, Joan; "Application of non-negative matrix factorization combined with Fisher's linear discriminant analysis for classification of olive oil excitation-emission fluorescence spectra", Journal of Chemometrics and Intelligent Laboratory Systems, 2006. 4

5. Chiang, Leo H.;Kotanchek, Mark E.;Kordon, Arthur K.; "Fault diagnosis based on Fisher discriminant analysis and support vector machines" Journal of Computers & Chemical Engineering, 2004 5

6. Yang, Jian ;Frangi, Alejandro F.; Yang, Jing-yu; "A new kernel Fisher discriminant algorithm with application to face recognition", 2004 6

7. Cawley, Gavin C.; Talbot, Nicola L. C.; "Efficient leave-one-out cross-validation of kernel fisher discriminant classifiers", Journal of Pattern Recognition , 2003 7

8. Kodipaka, S.; Vemuri, B.C.; Rangarajan, A.; Leonard, C.M.; Schmallfuss, I.; Eisenschenk, S.; "Kernel Fisher discriminant for shape-based classification in epilepsy" Hournal Medical Image Analysis, 2007. 8

Fisher's (Linear) Discriminant Analysis (FDA) - Multi-Class Problem - October 7, 2010

Obtaining Covariance Matrices

The within-class covariance matrix $\mathbf{S}_{W}$ is easy to obtain:

\begin{align} \mathbf{S}_{W} = \sum_{i=1}^{k} \mathbf{S}_{i} \end{align}

where $\mathbf{S}_{i} = \frac{1}{n_{i}}\sum_{j: y_{j}=i}(\mathbf{x}_{j} - \mathbf{\mu}_{i})(\mathbf{x}_{j} - \mathbf{\mu}_{i})^{T}$ and $\mathbf{\mu}_{i} = \frac{\sum_{j: y_{j}=i}\mathbf{x}_{j}}{n_{i}}$.

However, the between-class covariance matrix $\mathbf{S}_{B}$ is not easy to compute directly. To bypass this problem we use the following method. We know that the total covariance $\,\mathbf{S}_{T}$ of a given set of data is constant and known, and we can also decompose this variance into two parts: the within-class variance $\mathbf{S}_{W}$ and the between-class variance $\mathbf{S}_{B}$ in a way that is similar to ANOVA. We thus have:

\begin{align} \mathbf{S}_{T} = \mathbf{S}_{W} + \mathbf{S}_{B} \end{align}

where the total variance is given by

\begin{align} \mathbf{S}_{T} = \frac{1}{n} \sum_{i}(\mathbf{x_{i}-\mu})(\mathbf{x_{i}-\mu})^{T} \end{align}

We can now get $\mathbf{S}_{B}$ from the relationship:

\begin{align} \mathbf{S}_{B} = \mathbf{S}_{T} - \mathbf{S}_{W} \end{align}

Actually, there is another way to obtain $\mathbf{S}_{B}$. Suppose the data contains $\, k$ classes, and each class $\, j$ contains $\, n_{j}$ data points. We denote the overall mean vector by

\begin{align} \mathbf{\mu} = \frac{1}{n}\sum_{i}\mathbf{x_{i}} = \frac{1}{n}\sum_{j=1}^{k}n_{j}\mathbf{\mu}_{j} \end{align}

Thus the total covariance matrix $\mathbf{S}_{T}$ is

\begin{align} \mathbf{S}_{T} = \frac{1}{n} \sum_{i}(\mathbf{x_{i}-\mu})(\mathbf{x_{i}-\mu})^{T} \end{align}

Thus we obtain

\begin{align} & \mathbf{S}_{T} = \sum_{i=1}^{k}\sum_{j: y_{j}=i}(\mathbf{x}_{j} - \mathbf{\mu}_{i} + \mathbf{\mu}_{i} - \mathbf{\mu})(\mathbf{x}_{j} - \mathbf{\mu}_{i} + \mathbf{\mu}_{i} - \mathbf{\mu})^{T} \\& = \sum_{i=1}^{k}\sum_{j: y_{j}=i}(\mathbf{x}_{j}-\mathbf{\mu}_{i})(\mathbf{x}_{j}-\mathbf{\mu}_{i})^{T}+ \sum_{i=1}^{k}\sum_{j: y_{j}=i}(\mathbf{\mu}_{i}-\mathbf{\mu})(\mathbf{\mu}_{i}-\mathbf{\mu})^{T} \\& = \mathbf{S}_{W} + \sum_{i=1}^{k} n_{i}(\mathbf{\mu}_{i}-\mathbf{\mu})(\mathbf{\mu}_{i}-\mathbf{\mu})^{T} \end{align}

Since the total covariance $\mathbf{S}_{T}$ is the sum of the within-class covariance $\mathbf{S}_{W}$ and the between-class covariance $\mathbf{S}_{B}$, we can denote the second term in the final line of the derivation above as the between-class covariance matrix $\mathbf{S}_{B}$, thus we obtain

\begin{align} \mathbf{S}_{B} = \sum_{i=1}^{k} n_{i}(\mathbf{\mu}_{i}-\mathbf{\mu})(\mathbf{\mu}_{i}-\mathbf{\mu})^{T} \end{align}

Recall that in the two class case problem, we have

\begin{align} & \mathbf{S}_{B}^* = (\mathbf{\mu}_{1}-\mathbf{\mu}_{2})(\mathbf{\mu}_{1}-\mathbf{\mu}_{2})^{T} \\ & = (\mathbf{\mu}_{1}-\mathbf{\mu}+\mathbf{\mu}-\mathbf{\mu}_{2})(\mathbf{\mu}_{1}-\mathbf{\mu}+\mathbf{\mu}-\mathbf{\mu}_{2})^{T} \\ & = ((\mathbf{\mu}_{1}-\mathbf{\mu})-(\mathbf{\mu}_{2}-\mathbf{\mu}))((\mathbf{\mu}_{1}-\mathbf{\mu})-(\mathbf{\mu}_{2}-\mathbf{\mu}))^{T} \\ & = ((\mathbf{\mu}_{1}-\mathbf{\mu})-(\mathbf{\mu}_{2}-\mathbf{\mu}))((\mathbf{\mu}_{1}-\mathbf{\mu})^{T}-(\mathbf{\mu}_{2}-\mathbf{\mu})^{T}) \\ & = (\mathbf{\mu}_{1}-\mathbf{\mu})(\mathbf{\mu}_{1}-\mathbf{\mu})^{T}-(\mathbf{\mu}_{1}-\mathbf{\mu})(\mathbf{\mu}_{2}-\mathbf{\mu})^{T}-(\mathbf{\mu}_{2}-\mathbf{\mu})(\mathbf{\mu}_{1}-\mathbf{\mu})^{T}+(\mathbf{\mu}_{2}-\mathbf{\mu})(\mathbf{\mu}_{2}-\mathbf{\mu})^{T} \end{align}

\begin{align} & \mathbf{S}_{B} = n_{1}(\mathbf{\mu}_{1}-\mathbf{\mu})(\mathbf{\mu}_{1}-\mathbf{\mu})^{T} + n_{2}(\mathbf{\mu}_{2}-\mathbf{\mu})(\mathbf{\mu}_{2}-\mathbf{\mu})^{T} \end{align}

Apparently, they are very similar.

Now, we are trying to find the optimal transformation. Basically, we have

\begin{align} \mathbf{z}_{i} = \mathbf{W}^{T}\mathbf{x}_{i}, i=1,2,...,k-1 \end{align}

where $\mathbf{z}_{i}$ is a $(k-1)\times 1$ vector, $\mathbf{W}$ is a $d\times (k-1)$ transformation matrix, i.e. $\mathbf{W} = [\mathbf{w}_{1}, \mathbf{w}_{2},..., \mathbf{w}_{k-1}]$, and $\mathbf{x}_{i}$ is a $d\times 1$ column vector.

Thus we obtain

\begin{align} & \mathbf{S}_{W}^{\ast} = \sum_{i=1}^{k}\sum_{j: y_{j}=i}(\mathbf{W}^{T}\mathbf{x}_{j}-\mathbf{W}^{T}\mathbf{\mu}_{i})(\mathbf{W}^{T}\mathbf{x}_{j}-\mathbf{W}^{T}\mathbf{\mu}_{i})^{T} \\ & = \sum_{i=1}^{k}\sum_{j: y_{j}=i}(\mathbf{W}^{T}(\mathbf{x}_{j}-\mathbf{\mu}_{i}))(\mathbf{W}^{T}(\mathbf{x}_{j}-\mathbf{\mu}_{i}))^{T} \\ & = \sum_{i=1}^{k}\sum_{j: y_{j}=i}(\mathbf{W}^{T}(\mathbf{x}_{j}-\mathbf{\mu}_{i}))((\mathbf{x}_{j}-\mathbf{\mu}_{i})^{T}\mathbf{W}) \\ & = \sum_{i=1}^{k}\sum_{j: y_{j}=i}\mathbf{W}^{T}(\mathbf{x}_{j}-\mathbf{\mu}_{i})(\mathbf{x}_{j}-\mathbf{\mu}_{i})^{T}\mathbf{W} \\ & = \mathbf{W}^{T}\left[\sum_{i=1}^{k}\sum_{j: y_{j}=i}(\mathbf{x}_{j}-\mathbf{\mu}_{i})(\mathbf{x}_{j}-\mathbf{\mu}_{i})^{T}\right]\mathbf{W} \\ & = \mathbf{W}^{T}\mathbf{S}_{W}\mathbf{W} \end{align}

Similarly, we obtain

\begin{align} & \mathbf{S}_{B}^{\ast} = \sum_{i=1}^{k}n_{i}(\mathbf{W}^{T}\mathbf{\mu}_{i}-\mathbf{W}^{T}\mathbf{\mu})(\mathbf{W}^{T}\mathbf{\mu}_{i}-\mathbf{W}^{T}\mathbf{\mu})^{T} \\ & = \sum_{i=1}^{k}n_{i}\mathbf{W}^{T}(\mathbf{\mu}_{i}-\mathbf{\mu})(\mathbf{\mu}_{i}-\mathbf{\mu})^{T}\mathbf{W} \\ & = \mathbf{W}^{T}\left[ \sum_{i=1}^{k}n_{i}(\mathbf{\mu}_{i}-\mathbf{\mu})(\mathbf{\mu}_{i}-\mathbf{\mu})^{T}\right]\mathbf{W} \\ & = \mathbf{W}^{T}\mathbf{S}_{B}\mathbf{W} \end{align}

Now, we use the following as our measure:

\begin{align} \sum_{i=1}^{k}n_{i}\|(\mathbf{W}^{T}\mathbf{\mu}_{i}-\mathbf{W}^{T}\mathbf{\mu})^{T}\|^{2} \end{align}

The solution for this question is that the columns of the transformation matrix $\mathbf{W}$ are exactly the eigenvectors that correspond to largest $k-1$ eigenvalues with respect to

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. Please improve this article if you can. (What if we encounter complex eigenvalues? Then concept of being large does not dense. What is the solution in that case?) | small = | smallimage = | smallimageright = | smalltext = }}

\begin{align} \mathbf{S}_{W}^{-1}\mathbf{S}_{B}\mathbf{w}_{i} = \lambda_{i}\mathbf{w}_{i} \end{align}

Recall that the Frobenius norm of $X$ is

\begin{align} \|\mathbf{X}\|^2_{2} = Tr(\mathbf{X}^{T}\mathbf{X}) \end{align}

\begin{align} & \sum_{i=1}^{k}n_{i}\|(\mathbf{W}^{T}\mathbf{\mu}_{i}-\mathbf{W}^{T}\mathbf{\mu})^{T}\|^{2} \\ & = \sum_{i=1}^{k}n_{i}Tr[(\mathbf{W}^{T}\mathbf{\mu}_{i}-\mathbf{W}^{T}\mathbf{\mu})(\mathbf{W}^{T}\mathbf{\mu}_{i}-\mathbf{W}^{T}\mathbf{\mu})^{T}] \\ & = Tr[\sum_{i=1}^{k}n_{i}(\mathbf{W}^{T}\mathbf{\mu}_{i}-\mathbf{W}^{T}\mathbf{\mu})(\mathbf{W}^{T}\mathbf{\mu}_{i}-\mathbf{W}^{T}\mathbf{\mu})^{T}] \\ & = Tr[\sum_{i=1}^{k}n_{i}\mathbf{W}^{T}(\mathbf{\mu}_{i}-\mathbf{\mu})(\mathbf{\mu}_{i}-\mathbf{\mu})^{T}\mathbf{W}] \\ & = Tr[\mathbf{W}^{T}\sum_{i=1}^{k}n_{i}(\mathbf{\mu}_{i}-\mathbf{\mu})(\mathbf{\mu}_{i}-\mathbf{\mu})^{T}\mathbf{W}] \\ & = Tr[\mathbf{W}^{T}\mathbf{S}_{B}\mathbf{W}] \end{align}

Similarly, we can get $Tr[\mathbf{W}^{T}\mathbf{S}_{W}\mathbf{W}]$. Thus we have following classic criterion function that Fisher used

\begin{align} \phi(\mathbf{W}) = \frac{Tr[\mathbf{W}^{T}\mathbf{S}_{B}\mathbf{W}]}{Tr[\mathbf{W}^{T}\mathbf{S}_{W}\mathbf{W}]} \end{align}

Similar to the two class case problem, we have:

max $Tr[\mathbf{W}^{T}\mathbf{S}_{B}\mathbf{W}]$ subject to $Tr[\mathbf{W}^{T}\mathbf{S}_{W}\mathbf{W}]=1$

To solve this optimization problem a Lagrange multiplier $\Lambda$, which actually is a $d \times d$ diagonal matrix, is introduced:

\begin{align} L(\mathbf{W},\Lambda) = Tr[\mathbf{W}^{T}\mathbf{S}_{B}\mathbf{W}] - \Lambda\left\{ Tr[\mathbf{W}^{T}\mathbf{S}_{W}\mathbf{W}] - 1 \right\} \end{align}

Differentiating with respect to $\mathbf{W}$ we obtain:

\begin{align} \frac{\partial L}{\partial \mathbf{W}} = (\mathbf{S}_{B} + \mathbf{S}_{B}^{T})\mathbf{W} - \Lambda (\mathbf{S}_{W} + \mathbf{S}_{W}^{T})\mathbf{W} \end{align}

Note that the $\mathbf{S}_{B}$ and $\mathbf{S}_{W}$ are both symmetric matrices, thus set the first derivative to zero, we obtain:

\begin{align} \mathbf{S}_{B}\mathbf{W} - \Lambda\mathbf{S}_{W}\mathbf{W}=0 \end{align}

Thus,

\begin{align} \mathbf{S}_{B}\mathbf{W} = \Lambda\mathbf{S}_{W}\mathbf{W} \end{align}

where

$\mathbf{\Lambda} = \begin{pmatrix} \lambda_{1} & & 0\\ &\ddots&\\ 0 & &\lambda_{d} \end{pmatrix}$

and $\mathbf{W} = [\mathbf{w}_{1}, \mathbf{w}_{2},..., \mathbf{w}_{k-1}]$.

As a matter of fact, $\mathbf{\Lambda}$ must have $\mathbf{k-1}$ nonzero eigenvalues, because $rank({S}_{W}^{-1}\mathbf{S}_{B})=k-1$.

Therefore, the solution for this question is as same as the previous case. The columns of the transformation matrix $\mathbf{W}$ are exactly the eigenvectors that correspond to largest $k-1$ eigenvalues with respect to

\begin{align} \mathbf{S}_{W}^{-1}\mathbf{S}_{B}\mathbf{w}_{i} = \lambda_{i}\mathbf{w}_{i} \end{align}

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: Adding more general comments about the advantages and flaws of FDA would be effective here.. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }}

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: Would you please show how could we reconstruct our original data from the data that its dimentionality is reduced by FDA.. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }} {{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: When you reduce the dimensionality of data in most general form you lose some features of the data and you cannot reconstruct the data from redacted space unless the data have special features that help you in reconstruction like sparsity. In FDA it seems that we cannot reconstruct data in general form using reducted version of data. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }}

Generalization of Fisher's Linear Discriminant Analysis

Fisher's Linear Discriminant Analysis (Fisher, 1936) is very popular among users of discriminant analysis. Some of the reasons for this are its simplicity and lack of necessity for strict assumptions. However, it has optimality properties only if the underlying distributions of the groups are multivariate normal. It is also easy to verify that the discriminant rule obtained can be very harmed by only a small number of outlying observations. Outliers are very hard to detect in multivariate data sets and even when they are detected simply discarding them is not the most efficient way of handling the situation. Therefore, there is a need for robust procedures that can accommodate the outliers and are not strongly affected by them. Then, a generalization of Fisher's linear discriminant algorithm [[14]]is developed to lead easily to a very robust procedure.

Also notice that LDA can be seen as a dimensionality reduction technique. In general k-class problems, we have k means which lie on a linear subspace with dimension k-1. Given a data point, we are looking for the closest class mean to this point. In LDA, we project the data point to the linear subspace and calculate distances within that subspace. If the dimensionality of the data, d, is much larger than the number of classes, k, then we have a considerable drop in dimension.

Linear and Logistic Regression - October 12, 2010

Linear Regression

Linear regression is an approach for modeling the scalar value $y$ from a set of dependent variable $X$. In linear regression the goal is to find an appropriate set of dependent variables to $y$ and try to estimate its value from the related set. While in classification the goal is to classify data to different groups in which the inner similarity among the group members are more than variables which belong to different groups.

We will start by considering a very simple regression model, the linear regression model. According to Bayes Classification,
$P( Y=k | X=x )= \frac{f_{k}(x)\pi_{k}}{\Sigma_{k}f_{k}(x)\pi_{k}}$

For the purpose of classification, the linear regression model assumes that the regression function $\,E(Y|X)$ is linear in the inputs $\,\mathbf{x}_{1}, ..., \mathbf{x}_{p}$.

The simple linear regression model has the general form:

\begin{align} y_i = \beta^{T}\mathbf{x}_{i}+\beta_{0} \end{align}

and we can denote it as

\begin{align} \mathbf{y} = \beta^{T}\mathbf{X} \end{align}

where $\,\beta^{T} = ( \beta_1,..., \beta_{d},\beta_0)$ is a $1 \times (d+1)$ vector and $\mathbf{X}= \begin{pmatrix} \mathbf{x}_{1}, \dots,\mathbf{x}_{n}\\ 1, \dots, 1 \end{pmatrix}$ is a $(d+1) \times n$ Matrix,here $\mathbf{x}_{i}$ is a $d \times 1$ vector

Given input data $\,\mathbf{x}_{1}, ..., \mathbf{x}_{n}$ and $\,y_{1}, ..., y_{n}$ our goal is to find $\,\beta^{T}$ such that the linear model fits the data while minimizing sum of squared errors using the Least Squares method.

Note that vectors $\mathbf{x}_{i}$ could be numerical inputs, transformations of the original data, i.e. $\log \mathbf{x}_{i}$ or $\sin \mathbf{x}_{i}$, or basis expansions, i.e. $\mathbf{x}_{i}^{2}$ or $\mathbf{x}_{i}\times \mathbf{x}_{j}$.

We then try to minimize the residual sum-of-squares

\begin{align} \mathrm{RSS}(\beta)=(\mathbf{y}-\beta^{T}\mathbf{X})^{T}(\mathbf{y}-\beta^{T}\mathbf{X}) \end{align}

This is a quadratic function in the $\,d+1$ parameters. Differentiating with respect to $\,\beta$ we obtain

\begin{align} \frac{\partial \mathrm{RSS}}{\partial \beta} = -2\mathbf{X}(\mathbf{y}-\beta^{T}\mathbf{X})^{T} \end{align}
\begin{align} \frac{\partial^{2}\mathrm{RSS}}{\partial \beta \partial \beta^{T}}=2\mathbf{X}^{T}\mathbf{X} \end{align}

Set the first derivative to zero

\begin{align} \mathbf{X}(\mathbf{y}^{T}-\mathbf{X}^{T}\beta)=0 \end{align}

we obtain the solution

\begin{align} \hat \beta = (\mathbf{X}\mathbf{X}^{T})^{-1}\mathbf{X}\mathbf{y}^{T} \end{align}

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: we use :\begin{align} \mathbf{y} = \beta^{T}\mathbf{X} \end{align} in this course, but

\begin{align} \mathbf{y} = \mathbf{X}\beta \end{align} were used by the notes last year and then it has the result below. I am confused these results seem to hold if we use $\beta^{T}X$ rather than $X\Beta$. If we use $X\Beta$ then X has to be a n x (d+1) matrix and $\Beta$ is a (d+1) x 1 vector. Has this cleanup been fixed or does it still stand?. Please improve this article if you can. (12 Oct 2010)

| small = | smallimage = | smallimageright = | smalltext = }} {{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: It depends on the definition of :\begin{align} \beta^{T}\end{align} and/or \begin{align}\beta\end{align} as the second is nothing but the first, added to it :\begin{align}\beta0\end{align}, then :\begin{align}\beta\end{align} = [\begin{align} \beta0\end{align} \begin{align}\beta^{T}\end{align}] I think this is close to the right explanation, please make sure of it and post the right thing. Please improve this article if you can. (12 Oct 2010) | small = | smallimage = | smallimageright = | smalltext = }} {{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: in my notes, i have $\hat\mathbf{y} = \hat\beta\mathbf{X}$ NOT $\hat\mathbf{y} = \hat\beta^{T}\mathbf{X}$, I've fixed it below. The class last year defined their $X$ and $\beta$ differently. If you pay close attention to their definitions, you'll see their equations match up and so does ours!. Please improve this article if you can. (19 Oct 2010) | small = | smallimage = | smallimageright = | smalltext = }}

Thus the fitted values at the inputs are

\begin{align} \mathbf{\hat y} = \hat\beta\mathbf{X} = \mathbf{y}\mathbf{X}^{T}(\mathbf{X}^{T}\mathbf{X})^{-1}\mathbf{X} \end{align}

where $\mathbf{H} = \mathbf{X}^{T}(\mathbf{X}^{T}\mathbf{X})^{-1}\mathbf{X}$ is called the hat matrix.

• Note For classification purposes, this is not a correct model. Recall the following application of Bayes classifier:

$r(x)= P( Y=k | X=x )= \frac{f_{k}(x)\pi_{k}}{\Sigma_{k}f_{k}(x)\pi_{k}}$
It is clear that to make sense mathematically, $\displaystyle r(x)$ must be a value between 0 and 1. If this is estimated with the regression function $\displaystyle r(x)=E(Y|X=x)$ and $\mathbf{\hat\beta}$ is learned as above, then there is nothing that would restrict $\displaystyle r(x)$ to taking values between 0 and 1. This is more direct approach to classification since it do not need to estimate $\ f_k(x)$ and $\ \pi_k$. $\ 1 \times P(Y=1|X=x)+0 \times P(Y=0|X=x)=E(Y|X)$ This model does not classify Y between 0 and 1, so it is not good and sometimes it can lead to a decent classifier. $\ y_i=\frac{1}{n_1}$ $\ \frac{-1}{n_2}$

Logistic Regression

The logistic regression model arises from the desire to model the posterior probabilities of the $\displaystyle K$ classes via linear functions in $\displaystyle x$, while at the same time ensuring that they sum to one and remain in [0,1].Logistic regression models are usually fit by maximum likelihood, using the conditional likelihood ,using $\displaystyle Pr(Y|X)$. Since $\displaystyle Pr(Y|X)$ completely specifies the conditional distribution, the multinomial distribution is appropriate. This model is widely used in biostatistical applications for two classes. For instance: people survive or die, have a disease or not, have a risk factor or not.

logistic function

A logistic function or logistic curve is the most common sigmoid curve.

1. $y = \frac{1}{1+e^{-x}}$

2. $\frac{dy}{dx} = y(1-y)=\frac{e^{x}}{(1+e^{x})^{2}}$

3. $y(0) = \frac{1}{2}$

4. $\int y dx = ln(1 + e^{x})$

5. $y(x) = \frac{1}{2} + \frac{1}{4}x - \frac{1}{48}x^{3} + \frac{1}{48}x^{5} \cdots$

The logistic curve shows early exponential growth for negative t, which slows to linear growth of slope 1/4 near t = 0, then approaches y = 1 with an exponentially decaying gap.

Intuition behind Logistic Regression

Recall that, for classification purposes, the linear regression model presented in the above section is not correct because it does not force $\,r(x)$ to be between 0 and 1 and sum to 1. Consider the following log odds model (for two classes):

$\log\left(\frac{P(Y=1|X=x)}{P(Y=0|X=x)}\right)=\beta^Tx$

Calculating $\,P(Y=1|X=x)$ leads us to the logistic regression model, which as opposed to the linear regression model, allows the modelling of the posterior probabilities of the classes through linear methods and at the same time ensures that they sum to one and are between 0 and 1. It is a type of Generalized Linear Model (GLM).

The Logistic Regression Model

The logistic regression model for the two class case is defined as

Class 1 {{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: It could be useful to have sources for these graphs. We don't know if they are copyrighted. Please improve this article if you can. (October 13 2010) | small = | smallimage = | smallimageright = | smalltext = }} {{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: I Could not find any source for these graphs. However, they following the definition of the defined probability. I don't think the generated graph as it is here is copyrighted, but if you worried you can draw this figure by applying the function and post the result.. Please improve this article if you can. (October 18 2010) | small = | smallimage = | smallimageright = | smalltext =

}}
$P(Y=1 | X=x)$
$P(Y=1 | X=x) =\frac{\exp(\underline{\beta}^T \underline{x})}{1+\exp(\underline{\beta}^T \underline{x})}=P(x;\underline{\beta})$

Then we have that

Class 0 {{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: It could be useful to have sources for these graphs. We don't know if they are copyrighted. Please improve this article if you can. (October 13 2010) | small = | smallimage = | smallimageright = | smalltext =

}}
$P(Y=0 | X=x)$
$P(Y=0 | X=x) = 1-P(Y=1 | X=x)=1-\frac{\exp(\underline{\beta}^T \underline{x})}{1+\exp(\underline{\beta}^T \underline{x})}=\frac{1}{1+\exp(\underline{\beta}^T \underline{x})}$

Fitting a Logistic Regression

Logistic regression tries to fit a distribution. The common practice in statistics is to fit density function, posterior density of each class(Pr(Y|X), to data using maximum likelihood. The maximum likelihood of $\underline\beta$ maximizes the probability of obtaining the data $\displaystyle{x_{1},...,x_{n}}$ from the known distribution. Combining $\displaystyle P(Y=1 | X=x)$ and $\displaystyle P(Y=0 | X=x)$ as follows, we can consider the two classes at the same time:

$p(\underline{x_{i}};\underline{\beta}) = \left(\frac{\exp(\underline{\beta}^T \underline{x_i})}{1+\exp(\underline{\beta}^T \underline{x_i})}\right)^{y_i} \left(\frac{1}{1+\exp(\underline{\beta}^T \underline{x_i})}\right)^{1-y_i}$

Assuming the data $\displaystyle {x_{1},...,x_{n}}$ is drawn independently, the likelihood function is

\begin{align} \mathcal{L}(\theta)&=p({x_{1},...,x_{n}};\theta)\\ &=\displaystyle p(x_{1};\theta) p(x_{2};\theta)... p(x_{n};\theta) \quad \mbox{(by independence)}\\ &= \prod_{i=1}^n p(x_{i};\theta) \end{align}

Since it is more convenient to work with the log-likelihood function, take the log of both sides, we get

$\displaystyle l(\theta)=\displaystyle \sum_{i=1}^n \log p(x_{i};\theta)$

So,

\begin{align} l(\underline\beta)&=\displaystyle\sum_{i=1}^n y_{i}\log\left(\frac{\exp(\underline{\beta}^T \underline{x_i})}{1+\exp(\underline{\beta}^T \underline{x_i})}\right)+(1-y_{i})\log\left(\frac{1}{1+\exp(\underline{\beta}^T\underline{x_i})}\right)\\ &= \displaystyle\sum_{i=1}^n y_{i}(\underline{\beta}^T\underline{x_i}-\log(1+\exp(\underline{\beta}^T\underline{x_i}))+(1-y_{i})(-\log(1+\exp(\underline{\beta}^T\underline{x_i}))\\ &= \displaystyle\sum_{i=1}^n y_{i}\underline{\beta}^T\underline{x_i}-y_{i} \log(1+\exp(\underline{\beta}^T\underline{x_i}))- \log(1+\exp(\underline{\beta}^T\underline{x_i}))+y_{i} \log(1+\exp(\underline{\beta}^T\underline{x_i}))\\ &=\displaystyle\sum_{i=1}^n y_{i}\underline{\beta}^T\underline{x_i}- \log(1+\exp(\underline{\beta}^T\underline{x_i}))\\ \end{align}

To maximize the log-likelihood, set its derivative to 0.

\begin{align} \frac{\partial l}{\partial \underline{\beta}} &= \sum_{i=1}^n \left[{y_i} \underline{x}_i- \frac{\exp(\underline{\beta}^T \underline{x_i})}{1+\exp(\underline{\beta}^T \underline{x}_i)}\underline{x}_i\right]\\ &=\sum_{i=1}^n \left[{y_i} \underline{x}_i - p(\underline{x}_i;\underline{\beta})\underline{x}_i\right] \end{align}

There are n+1 nonlinear equations in $/ \beta$. The first column is vector 1, then $\ \sum_{i=1}^n {y_i} =\sum_{i=1}^n p(\underline{x}_i;\underline{\beta})$ i.e. the expected number of class ones matches the observed number.

To solve this equation, the Newton-Raphson algorithm is used which requires the second derivative in addition to the first derivative. This is demonstrated in the next section.

Extension

• When we are dealing with a problem with more than two classes, we need to generalize our logistic regression to a Multinomial Logit model.
• Limitations of Logistic Regression:
1. We know that there is no assumptions are made about the distributions of the features of the data (i.e. the explanatory variables). However, the features should not be highly correlated with one another because this could cause problems with estimation.
2. Large number of data points (i.e.the sample sizes) are required for logistic regression to provide sufficient numbers in both classes. The more number of features/dimensions of the data, the larger the sample size required.

Lecture summary

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: Can anybody provide a better lecture summary? The one below is to just get it started. Please improve this article if you can. (October 18 2010) | small = | smallimage = | smallimageright = | smalltext = }} In this lecture an introduction of the linear regression was presented as well as defining the density function for two-class problem. Maximum likelihood was used to define the distribution parameters (i.e. fitting density function to the logistic class.

Logistic Regression Cont. - October 14, 2010

Logistic Regression Model

Recall that in the last lecture, we learned the logistic regression model.

• $P(Y=1 | X=x)=P(\underline{x}_i;\underline{\beta})=\frac{exp(\underline{\beta}^T \underline{x})}{1+exp(\underline{\beta}^T \underline{x})}$
• $P(Y=0 | X=x)=1-P(\underline{x}_i;\underline{\beta})=\frac{1}{1+exp(\underline{\beta}^T \underline{x})}$

Estimating Parameters $\underline{\beta}$

Criteria: find a $\underline{\beta}$ that maximizes the conditional likelihood of Y given X using the training data.

From above, we have the first derivative of the log-likelihood:

$\frac{\partial l}{\partial \underline{\beta}} = \sum_{i=1}^n \left[{y_i} \underline{x}_i- \frac{exp(\underline{\beta}^T \underline{x_i})}{1+exp(\underline{\beta}^T \underline{x}_i)}\underline{x}_i\right]$ $=\sum_{i=1}^n \left[{y_i} \underline{x}_i - P(\underline{x}_i;\underline{\beta})\underline{x}_i\right]$

Newton-Raphson Algorithm:

If we want to find $\ x^*$ such that $\ f(x^*)=0$

We first pick a starting point $x^* = x^{old}$ and and we solve:

$\ x^{*} \leftarrow x^{old}-\frac {f(x^{old})}{\partial f(x^{old})}$
$\ x^{old} \leftarrow x^{*}$
This is repeated till convergence

If we want to maximize or minimize $\ f(x)$, then solve for $\ \partial f(x)=0$

$\ X^{new} \leftarrow x^{old}-\frac {\partial f(x^{old})}{\partial^2 f(x^{old})}$

In vector notation the above can be written as

$X^{new} \leftarrow X^{old} - H^{-1}\Delta$
H is the Hessian matrix or second derivative matrix and $\Delta$ is the gradient both evaluated at $X^{old}$

note: If the Hessian is not invertible the generalized inverse or pseudo inverse can be used

As shown above ,the Newton-Raphson algorithm requires the second-derivative or Hessian.

$\frac{\partial^{2} l}{\partial \underline{\beta} \partial \underline{\beta}^T }= \sum_{i=1}^n - \underline{x_i} \frac{(exp(\underline{\beta}^T\underline{x}_i) \underline{x}_i^T)(1+exp(\underline{\beta}^T \underline{x}_i))-\underline{x}_i exp(\underline{\beta}^T\underline{x}_i)exp(\underline{\beta}^T\underline{x}_i)}{(1+exp(\underline{\beta}^T \underline{x}))^2}$

(note: $\frac{\partial\underline{\beta}^T\underline{x}_i}{\partial \underline{\beta}^T}=\underline{x}_i^T$ you can check it here, it's a very useful website including a Matrix Reference Manual that you can find information about linear algebra and the properties of real and complex matrices.)

$=\sum_{i=1}^n - \underline{x}_i \frac{(-\underline{x}_i exp(\underline{\beta}^T\underline{x}_i) \underline{x}_i^T)}{(1+exp(\underline{\beta}^T \underline{x}))(1+exp(\underline{\beta}^T \underline{x}))}$ (by cancellation)
$=\sum_{i=1}^n - \underline{x}_i \underline{x}_i^T P(\underline{x}_i;\underline{\beta}）)[1-P(\underline{x}_i;\underline{\beta})]）$(since $P(\underline{x}_i;\underline{\beta})=\frac{exp(\underline{\beta}^T \underline{x})}{1+exp(\underline{\beta}^T \underline{x})}$ and $1-P(\underline{x}_i;\underline{\beta})=\frac{1}{1+exp(\underline{\beta}^T \underline{x})}$)

The same second derivative can be achieved if we reduce the occurrences of beta to 1 by the identity$\frac{a}{1+a}=1-\frac{1}{1+a}$

And solving $\frac{\partial}{\partial \underline{\beta}^T}\sum_{i=1}^n \left[{y_i} \underline{x}_i-\left[1-\frac{1}{1+exp(\underline{\beta}^T \underline{x}_i)}\right]\underline{x}_i\right]$

Starting with $\,\underline{\beta}^{old}$, the Newton-Raphson update is

$\,\underline{\beta}^{new}\leftarrow \,\underline{\beta}^{old}- (\frac{\partial ^2 l}{\partial \underline{\beta}\partial \underline{\beta}^T})^{-1}(\frac{\partial l}{\partial \underline{\beta}})$ where the derivatives are evaluated at $\,\underline{\beta}^{old}$

The iteration will terminate when $\underline{\beta}^{new}$ is very close to $\underline{\beta}^{old}$.

The iteration can be described in matrix form.

• Let $\,\underline{Y}$ be the column vector of $\,y_i$. ($n\times1$)
• Let $\,X$ be the ${d}\times{n}$ input matrix.
• Let $\,\underline{P}$ be the ${n}\times{1}$ vector with $i$th element $P(\underline{x}_i;\underline{\beta}^{old})$.
• Let $\,W$ be an ${n}\times{n}$ diagonal matrix with $i$th element $P(\underline{x}_i;\underline{\beta}^{old})[1-P(\underline{x}_i;\underline{\beta}^{old})]$

then

$\frac{\partial l}{\partial \underline{\beta}} = X(\underline{Y}-\underline{P})$

$\frac{\partial ^2 l}{\partial \underline{\beta}\partial \underline{\beta}^T} = -XWX^T$

The Newton-Raphson step is

$\underline{\beta}^{new} \leftarrow \underline{\beta}^{old}+(XWX^T)^{-1}X(\underline{Y}-\underline{P})$

This equation is sufficient for computation of the logistic regression model. However, we can simplify further to uncover an interesting feature of this equation.

\begin{align} \underline{\beta}^{new} &= (XWX^T)^{-1}(XWX^T)\underline{\beta}^{old}+(XWX^T)^{-1}XWW^{-1}(\underline{Y}-\underline{P})\\ &=(XWX^T)^{-1}XW[X^T\underline{\beta}^{old}+W^{-1}(\underline{Y}-\underline{P})]\\ &=(XWX^T)^{-1}XWZ \end{align}

where $Z=X\underline{\beta}^{old}+W^{-1}(\underline{Y}-\underline{P})$

This is a adjusted response and it is solved repeatedly when $\ p$, $\ W$, and $\ z$ changes. This algorithm is called iteratively reweighted least squares because it solves the weighted least squares problem repeatedly.

Recall that linear regression by least square finds the following minimum: $\min_{\underline{\beta}}(\underline{y}-\underline{\beta}^T X)^T(\underline{y}-\underline{\beta}^TX)$

we have $\underline\hat{\beta}=(XX^T)^{-1}X\underline{y}$

Similarly, we can say that $\underline{\beta}^{new}$ is the solution of a weighted least square problem:

$\underline{\beta}^{new} \leftarrow arg \min_{\underline{\beta}}(Z-X\underline{\beta}^T)W(Z-X\underline{\beta})$

Pseudo Code

1. $\underline{\beta} \leftarrow 0$
2. Set $\,\underline{Y}$, the label associated with each observation $\,i=1...n$.
3. Compute $\,\underline{P}$ according to the equation $P(\underline{x}_i;\underline{\beta})=\frac{exp(\underline{\beta}^T \underline{x})}{1+exp(\underline{\beta}^T \underline{x})}$ for all $\,i=1...n$.
4. Compute the diagonal matrix $\,W$ by setting $\,w_i,i$ to $P(\underline{x}_i;\underline{\beta}）)[1-P(\underline{x}_i;\underline{\beta})]$ for all $\,i=1...n$.
5. $Z \leftarrow X^T\underline{\beta}+W^{-1}(\underline{Y}-\underline{P})$.
6. $\underline{\beta} \leftarrow (XWX^T)^{-1}XWZ$.
7. If the new $\underline{\beta}$ value is sufficiently close to the old value, stop; otherwise go back to step 3.

Comparison with Linear Regression

• Similarities
1. They are both to attempt to estimate $\,P(Y=k|X=x)$ (For logistic regression, we just mentioned about the case that $\,k=0$ or $\,k=1$ now).
2. They are both have linear boundaries.
note:For linear regression, we assume the model is linear. The boundary is $P(Y=k|X=x)=\underline{\beta}^T\underline{x}_i+\underline{\beta}_0=0.5$ (linear)
For logistic regression, the boundary is $P(Y=k|X=x)=\frac{exp(\underline{\beta}^T \underline{x})}{1+exp(\underline{\beta}^T \underline{x})}=0.5 \Rightarrow exp(\underline{\beta}^T \underline{x})=1\Rightarrow \underline{\beta}^T \underline{x}=0$ (linear)
• Differences
1. Linear regression: $\,P(Y=k|X=x)$ is linear function of $\,x$, $\,P(Y=k|X=x)$ is not guaranteed to fall between 0 and 1 and to sum up to 1. There exists a closed form solution for least squares.
1. Logistic regression: $\,P(Y=k|X=x)$ is a nonlinear function of $\,x$, and it is guaranteed to range from 0 to 1 and to sum up to 1. No closed form solution exists

Comparison with LDA

1. The linear logistic model only consider the conditional distribution $\,P(Y=k|X=x)$. No assumption is made about $\,P(X=x)$.
2. The LDA model specifies the joint distribution of $\,X$ and $\,Y$.
3. Logistic regression maximizes the conditional likelihood of $\,Y$ given $\,X$: $\,P(Y=k|X=x)$
4. LDA maximizes the joint likelihood of $\,Y$ and $\,X$: $\,P(Y=k,X=x)$.
5. If $\,\underline{x}$ is d-dimensional,the number of adjustable parameter in logistic regression is $\,d$. The number of parameters grows linearly w.r.t dimension.
6. If $\,\underline{x}$ is d-dimensional,the number of adjustable parameter in LDA is $\,(2d)+d(d+1)/2+2=(d^2+5d+4)/2$. The number of parameters grows quadratically w.r.t dimension.
7. LDA estimate parameters more efficiently by using more information about data and samples without class labels can be also used in LDA.

{{

 Template:namespace detect


| type = style | image = | imageright = | style = | textstyle = | text = This article may require cleanup to meet Wikicoursenote's quality standards. The specific problem is: Could somebody please validate the following points. Please improve this article if you can. (October 2010) | small = | smallimage = | smallimageright = | smalltext = }}

1. As logistic regression relies on fewer assumptions, it seems to be more robust.
2. In practice, Logistic regression and LDA often give the similar results.

By example

Now we compare LDA and Logistic regression by an example. Again, we use them on the 2_3 data.

 >>load 2_3;
>>[U, sample] = princomp(X');
>>sample = sample(:,1:2);
>>plot (sample(1:200,1), sample(1:200,2), '.');
>>hold on;
>>plot (sample(201:400,1), sample(201:400,2), 'r.');

First, we do PCA on the data and plot the data points that represent 2 or 3 in different colors. See the previous example for more details.
 >>group = ones(400,1);
>>group(201:400) = 2;

Group the data points.
 >>[B,dev,stats] = mnrfit(sample,group);
>>x=[ones(1,400); sample'];

Now we use mnrfit to use logistic regression to classfy the data. This function can return B which is a $(d+1)\times{(k–1)}$ matrix of estimates, where each column corresponds to the estimated intercept term and predictor coefficients. In this case, B is a $3\times{1}$ matrix.
 >> B
B =0.1861
-5.5917
-3.0547

This is our $\underline{\beta}$. So the posterior probabilities are:
$P(Y=1 | X=x)=\frac{exp(0.1861-5.5917X_1-3.0547X_2)}{1+exp(0.1861-5.5917X_1-3.0547X_2)}$.
$P(Y=2 | X=x)=\frac{1}{1+exp(0.1861-5.5917X_1-3.0547X_2)}$
The classification rule is:
$\hat Y = 1$, if $\,0.1861-5.5917X_1-3.0547X_2\gt =0$
$\hat Y = 2$, if $\,0.1861-5.5917X_1-3.0547X_2\lt 0$
 >>f = sprintf('0 = %g+%g*x+%g*y', B(1), B(2), B(3));
>>ezplot(f,[min(sample(:,1)), max(sample(:,1)), min(sample(:,2)), max(sample(:,2))])

Plot the decision boundary by logistic regression.
This is a decision boundary by logistic regression.The line shows how the two classes split.
 >>[class, error, POSTERIOR, logp, coeff] = classify(sample, sample, group, 'linear');
>>k = coeff(1,2).const;
>>l = coeff(1,2).linear;
>>f = sprintf('0 = %g+%g*x+%g*y', k, l(1), l(2));
>>h=ezplot(f, [min(sample(:,1)), max(sample(:,1)), min(sample(:,2)), max(sample(:,2))]);

Plot the decision boundary by LDA. See the previous example for more information about LDA in matlab.
From this figure, we can see that the results of Logistic Regression and LDA are very similar.

Lecture Summary

Traditionally logistic regression parameters are estimated using maximum likelihood. However , other optimization techniques may be used as well.
Since there is no closed form solution for finding the zero of the first derivative of the log likelihood the Newton Raphson algorithm is used. Since the problem is convex Newtons is guaranteed to converge to a global optimum.
Logistic regression requires less parameters than LDA or QDA and is therefore more favorable for high dimensional data.

Supplements

A detailed proof that logistic regression is convex is available here. See '1 Binary LR' for the case we discussed in lecture.