# 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.

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
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
anyone know any internet site where one can find nanotechnology papers?
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
what does nano mean?
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
it is a goid question and i want to know the answer as well
Maciej
Abigail
for teaching engĺish at school how nano technology help us
Anassong
How can I make nanorobot?
Lily
Do somebody tell me a best nano engineering book for beginners?
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
how can I make nanorobot?
Lily
what is fullerene does it is used to make bukky balls
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
Got questions? Join the online conversation and get instant answers!   By   By Rhodes By Dravida Mahadeo-J... By By By