# Machine learning lecture 1 course notes  (Page 13/13)

 Page 13 / 13

## Softmax regression

Let's look at one more example of a GLM. Consider a classification problem in which the response variable $y$ can take on any one of $k$ values, so $y\in \left\{1,2,...,k\right\}$ . For example, rather than classifying email into the two classes spam or not-spam—which would have been a binaryclassification problem—we might want to classify it into three classes, such as spam, personal mail, and work-related mail. The response variable isstill discrete, but can now take on more than two values. We will thus model it as distributed according to a multinomial distribution.

Let's derive a GLM for modelling this type of multinomial data. To do so, we will begin by expressing the multinomial as an exponential family distribution.

To parameterize a multinomial over $k$ possible outcomes, one could use $k$ parameters ${\Phi }_{1},...,{\Phi }_{k}$ specifying the probability of each of the outcomes. However, these parameters would be redundant, or more formally, they would not beindependent (since knowing any $k-1$ of the ${\Phi }_{i}$ 's uniquely determines the last one, as they must satisfy ${\sum }_{i=1}^{k}{\Phi }_{i}$ = 1). So, we will instead parameterize the multinomial with only $k-1$ parameters, ${\Phi }_{1},...,{\Phi }_{k-1}$ , where ${\Phi }_{i}=p\left(y=i;\Phi \right)$ , and $p\left(y=k;\Phi \right)=1-{\sum }_{i=1}^{k-1}{\Phi }_{i}$ . For notational convenience, we will also let ${\Phi }_{k}=1-{\sum }_{i=1}^{k-1}{\Phi }_{i}$ , but we should keep in mind that this is not a parameter, and that it is fully specified by ${\Phi }_{1},...,{\Phi }_{k-1}$ .

To express the multinomial as an exponential family distribution, we will define $T\left(y\right)\in {\mathbb{R}}^{k-1}$ as follows:

$T\left(1\right)=\left[\begin{array}{c}1\\ 0\\ 0\\ ⋮\\ 0\end{array}\right],\phantom{\rule{0.277778em}{0ex}}T\left(2\right)=\left[\begin{array}{c}0\\ 1\\ 0\\ ⋮\\ 0\end{array}\right],\phantom{\rule{0.277778em}{0ex}}T\left(3\right)=\left[\begin{array}{c}0\\ 0\\ 1\\ ⋮\\ 0\end{array}\right],\phantom{\rule{0.277778em}{0ex}}\cdots ,T\left(k-1\right)=\left[\begin{array}{c}0\\ 0\\ 0\\ ⋮\\ 1\end{array}\right],\phantom{\rule{0.277778em}{0ex}}T\left(k\right)=\left[\begin{array}{c}0\\ 0\\ 0\\ ⋮\\ 0\end{array}\right],\phantom{\rule{0.277778em}{0ex}}$

Unlike our previous examples, here we do not have $T\left(y\right)=y$ ; also, $T\left(y\right)$ is now a $k-1$ dimensional vector, rather than a real number. We will write ${\left(T\left(y\right)\right)}_{i}$ to denote the $i$ -th element of the vector $T\left(y\right)$ .

We introduce one more very useful piece of notation. An indicator function $1\left\{·\right\}$ takes on a value of 1 if its argument is true, and 0 otherwise ( $1\left\{\mathrm{True}\right\}=1$ , $1\left\{\mathrm{False}\right\}=0$ ). For example, $1\left\{2=3\right\}=0$ , and $1\left\{3=5-2\right\}=1$ . So, we can also write the relationship between $T\left(y\right)$ and $y$ as ${\left(T\left(y\right)\right)}_{i}=1\left\{y=i\right\}$ . (Before you continue reading, please make sure you understand why this is true!) Further, wehave that $\mathrm{E}\left[{\left(T\left(y\right)\right)}_{i}\right]=P\left(y=i\right)={\Phi }_{i}$ .

We are now ready to show that the multinomial is a member of the exponential family. We have:

$\begin{array}{ccc}\hfill p\left(y;\Phi \right)& =& {\Phi }_{1}^{1\left\{y=1\right\}}{\Phi }_{2}^{1\left\{y=2\right\}}\cdots {\Phi }_{k}^{1\left\{y=k\right\}}\hfill \\ & =& {\Phi }_{1}^{1\left\{y=1\right\}}{\Phi }_{2}^{1\left\{y=2\right\}}\cdots {\Phi }_{k}^{1-{\sum }_{i=1}^{k-1}1\left\{y=i\right\}}\hfill \\ & =& {\Phi }_{1}^{{\left(T\left(y\right)\right)}_{1}}{\Phi }_{2}^{{\left(T\left(y\right)\right)}_{2}}\cdots {\Phi }_{k}^{1-{\sum }_{i=1}^{k-1}{\left(T\left(y\right)\right)}_{i}}\hfill \\ & =& exp\left({\left(T\left(y\right)\right)}_{1}log\left({\Phi }_{1}\right)+{\left(T\left(y\right)\right)}_{2}log\left({\Phi }_{2}\right)+\hfill \\ & & \phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\cdots +\left(1-{\sum }_{i=1}^{k-1}{\left(T\left(y\right)\right)}_{i}\right)log\left({\Phi }_{k}\right)\right)\hfill \\ & =& exp\left({\left(T\left(y\right)\right)}_{1}log\left({\Phi }_{1}/{\Phi }_{k}\right)+{\left(T\left(y\right)\right)}_{2}log\left({\Phi }_{2}/{\Phi }_{k}\right)+\hfill \\ & & \phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\phantom{\rule{0.277778em}{0ex}}\cdots +{\left(T\left(y\right)\right)}_{k-1}log\left({\Phi }_{k-1}/{\Phi }_{k}\right)+log\left({\Phi }_{k}\right)\right)\hfill \\ & =& b\left(y\right)exp\left({\eta }^{T}T\left(y\right)-a\left(\eta \right)\right)\hfill \end{array}$

where

$\begin{array}{ccc}\hfill \eta & =& \left[\begin{array}{c}log\left({\Phi }_{1}/{\Phi }_{k}\right)\\ log\left({\Phi }_{2}/{\Phi }_{k}\right)\\ ⋮\\ log\left({\Phi }_{k-1}/{\Phi }_{k}\right)\end{array}\right],\hfill \\ \hfill a\left(\eta \right)& =& -log\left({\Phi }_{k}\right)\hfill \\ \hfill b\left(y\right)& =& 1.\hfill \end{array}$

This completes our formulation of the multinomial as an exponential family distribution.

The link function is given (for $i=1,...,k$ ) by

${\eta }_{i}=log\frac{{\Phi }_{i}}{{\Phi }_{k}}.$

For convenience, we have also defined ${\eta }_{k}=log\left({\Phi }_{k}/{\Phi }_{k}\right)=0$ . To invert the link function and derive the response function, we therefore havethat

$\begin{array}{ccc}\hfill {e}^{{\eta }_{i}}& =& \frac{{\Phi }_{i}}{{\Phi }_{k}}\hfill \\ \hfill {\Phi }_{k}{e}^{{\eta }_{i}}& =& {\Phi }_{i}\hfill \\ \hfill {\Phi }_{k}\sum _{i=1}^{k}{e}^{{\eta }_{i}}& =& \sum _{i=1}^{k}{\Phi }_{i}=1\hfill \end{array}$

This implies that ${\Phi }_{k}=1/{\sum }_{i=1}^{k}{e}^{{\eta }_{i}}$ , which can be substituted back into Equation  [link] to give the response function

${\Phi }_{i}=\frac{{e}^{{\eta }_{i}}}{{\sum }_{j=1}^{k}{e}^{{\eta }_{j}}}$

This function mapping from the $\eta$ 's to the $\Phi$ 's is called the softmax function.

To complete our model, we use Assumption 3, given earlier, that the ${\eta }_{i}$ 's are linearly related to the $x$ 's. So, have ${\eta }_{i}={\theta }_{i}^{T}x$ (for $i=1,...,k-1$ ), where ${\theta }_{1},...,{\theta }_{k-1}\in {\mathbb{R}}^{n+1}$ are the parameters of our model. For notational convenience, we can also define ${\theta }_{k}=0$ , so that ${\eta }_{k}={\theta }_{k}^{T}x=0$ , as given previously. Hence, our model assumes that the conditional distribution of $y$ given $x$ is given by

$\begin{array}{ccc}\hfill p\left(y=i|x;\theta \right)& =& {\Phi }_{i}\hfill \\ & =& \frac{{e}^{{\eta }_{i}}}{{\sum }_{j=1}^{k}{e}^{{\eta }_{j}}}\hfill \\ & =& \frac{{e}^{{\theta }_{i}^{T}x}}{{\sum }_{j=1}^{k}{e}^{{\theta }_{j}^{T}x}}\hfill \end{array}$

This model, which applies to classification problems where $y\in \left\{1,...,k\right\}$ , is called softmax regression . It is a generalization of logistic regression.

Our hypothesis will output

$\begin{array}{ccc}\hfill {h}_{\theta }\left(x\right)& =& \mathrm{E}\left[T\left(y\right)|x;\theta \right]\hfill \\ & =& \mathrm{E}\left[\left(\begin{array}{c}1\left\{y,=,1\right\}\\ 1\left\{y,=,2\right\}\\ ⋮\\ 1\left\{y,=,k,-,1\right\}\end{array}|,\phantom{\rule{0.166667em}{0ex}},x,;,\theta \right]\hfill \\ & =& \left[\begin{array}{c}{\Phi }_{1}\\ {\Phi }_{2}\\ ⋮\\ {\Phi }_{k-1}\end{array}\right]\hfill \\ & =& \left[\begin{array}{c}\frac{exp{\theta }_{1}^{T}x}{{\sum }_{j=1}^{k}exp{\theta }_{j}^{T}x}\\ \frac{exp{\theta }_{2}^{T}x}{{\sum }_{j=1}^{k}exp{\theta }_{j}^{T}x}\\ ⋮\\ \frac{exp{\theta }_{k-1}^{T}x}{{\sum }_{j=1}^{k}exp{\theta }_{j}^{T}x}\end{array}\right].\hfill \end{array}$

In other words, our hypothesis will output the estimated probability that $p\left(y=i|x;\theta \right)$ , for every value of $i=1,...,k$ . (Even though ${h}_{\theta }\left(x\right)$ as defined above is only $k-1$ dimensional, clearly $p\left(y=k|x;\theta \right)$ can be obtained as $1-{\sum }_{i=1}^{k-1}{\Phi }_{i}$ .)

Lastly, let's discuss parameter fitting. Similar to our original derivation of ordinary least squares and logistic regression, if we have a training set of $m$ examples $\left\{\left({x}^{\left(i\right)},{y}^{\left(i\right)}\right);i=1,...,m\right\}$ and would like to learn the parameters ${\theta }_{i}$ of this model, we would begin by writing down the log-likelihood

$\begin{array}{ccc}\hfill \ell \left(\theta \right)& =& \sum _{i=1}^{m}logp\left({y}^{\left(i\right)}|{x}^{\left(i\right)};\theta \right)\hfill \\ & =& \sum _{i=1}^{m}log\prod _{l=1}^{k}{\left(\frac{{e}^{{\theta }_{l}^{T}{x}^{\left(i\right)}}}{{\sum }_{j=1}^{k}{e}^{{\theta }_{j}^{T}{x}^{\left(i\right)}}}\right)}^{1\left\{{y}^{\left(i\right)}=l\right\}}\hfill \end{array}$

To obtain the second line above, we used the definition for $p\left(y|x;\theta \right)$ given in Equation  [link] . We can now obtain the maximum likelihood estimate of the parameters by maximizing $\ell \left(\theta \right)$ in terms of $\theta$ , using a method such as gradient ascent or Newton's method.

where we get a research paper on Nano chemistry....?
what are the products of Nano chemistry?
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
da
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Bhagvanji
Preparation and Applications of Nanomaterial for Drug Delivery
revolt
da
Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
I only see partial conversation and what's the question here!
what about nanotechnology for water purification
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
Nasa has use it in the 60's, copper as water purification in the moon travel.
Alexandre
nanocopper obvius
Alexandre
what is the stm
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
why we need to study biomolecules, molecular biology in nanotechnology?
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
why?
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
how did you get the value of 2000N.What calculations are needed to arrive at it
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!