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

 Page 5 / 13

## Least squares revisited

Armed with the tools of matrix derivatives, let us now proceed to find in closed-form the value of $\theta$ that minimizes $J\left(\theta \right)$ . We begin by re-writing $J$ in matrix-vectorial notation.

Given a training set, define the design matrix $X$ to be the $m$ -by- $n$ matrix (actually $m$ -by- $n+1$ , if we include the intercept term) that contains the training examples' input values in its rows:

$X=\left[\begin{array}{ccc}—& {\left(x,\left(1\right)\right)}^{T}& —\\ —& {\left(x,\left(2\right)\right)}^{T}& —\\ & ⋮& \\ —& {\left(x,\left(m\right)\right)}^{T}& —\end{array}\right].$

Also, let $\stackrel{\to }{y}$ be the $m$ -dimensional vector containing all the target values from the training set:

$\stackrel{\to }{y}=\left[\begin{array}{c}{y}^{\left(1\right)}\\ {y}^{\left(2\right)}\\ ⋮\\ {y}^{\left(m\right)}\end{array}\right].$

Now, since ${h}_{\theta }\left({x}^{\left(i\right)}\right)={\left({x}^{\left(i\right)}\right)}^{T}\theta$ , we can easily verify that

$\begin{array}{ccc}\hfill X\theta -\stackrel{\to }{y}& =& \left[\begin{array}{c}{\left({x}^{\left(1\right)}\right)}^{T}\theta \\ ⋮\\ {\left({x}^{\left(m\right)}\right)}^{T}\theta \end{array}\right]-\left[\begin{array}{c}{y}^{\left(1\right)}\\ ⋮\\ {y}^{\left(m\right)}\end{array}\right]\hfill \\ & =& \left[\begin{array}{c}{h}_{\theta }\left({x}^{\left(1\right)}\right)-{y}^{\left(1\right)}\\ ⋮\\ {h}_{\theta }\left({x}^{\left(m\right)}\right)-{y}^{\left(m\right)}\end{array}\right].\hfill \end{array}$

Thus, using the fact that for a vector $z$ , we have that ${z}^{T}z={\sum }_{i}{z}_{i}^{2}$ :

$\begin{array}{ccc}\hfill \frac{1}{2}{\left(X\theta -\stackrel{\to }{y}\right)}^{T}\left(X\theta -\stackrel{\to }{y}\right)& =& \frac{1}{2}\sum _{i=1}^{m}{\left({h}_{\theta }\left({x}^{\left(i\right)}\right)-{y}^{\left(i\right)}\right)}^{2}\hfill \\ & =& J\left(\theta \right)\hfill \end{array}$

Finally, to minimize $J$ , let's find its derivatives with respect to $\theta$ . Combining the second and third equation in  [link] , we find that

${\nabla }_{{A}^{T}}\mathrm{tr}AB{A}^{T}C={B}^{T}{A}^{T}{C}^{T}+B{A}^{T}C$

Hence,

$\begin{array}{ccc}\hfill {\nabla }_{\theta }J\left(\theta \right)& =& {\nabla }_{\theta }\frac{1}{2}{\left(X\theta -\stackrel{\to }{y}\right)}^{T}\left(X\theta -\stackrel{\to }{y}\right)\hfill \\ & =& \frac{1}{2}{\nabla }_{\theta }\phantom{\rule{0.166667em}{0ex}}\left({\theta }^{T},{X}^{T},X,\theta ,-,{\theta }^{T},{X}^{T},\stackrel{\to }{y},-,{\stackrel{\to }{y}}^{T},X,\theta ,+,{\stackrel{\to }{y}}^{T},\stackrel{\to }{y}\right)\hfill \\ & =& \frac{1}{2}{\nabla }_{\theta }\phantom{\rule{0.166667em}{0ex}}\mathrm{tr}\left({\theta }^{T},{X}^{T},X,\theta ,-,{\theta }^{T},{X}^{T},\stackrel{\to }{y},-,{\stackrel{\to }{y}}^{T},X,\theta ,+,{\stackrel{\to }{y}}^{T},\stackrel{\to }{y}\right)\hfill \\ & =& \frac{1}{2}{\nabla }_{\theta }\phantom{\rule{0.166667em}{0ex}}\left(\mathrm{tr},\phantom{\rule{0.166667em}{0ex}},{\theta }^{T},{X}^{T},X,\theta ,-,2,\mathrm{tr},\phantom{\rule{0.166667em}{0ex}},{\stackrel{\to }{y}}^{T},X,\theta \right)\hfill \\ & =& \frac{1}{2}\left({X}^{T},X,\theta ,+,{X}^{T},X,\theta ,-,2,{X}^{T},\stackrel{\to }{y}\right)\hfill \\ & =& {X}^{T}X\theta -{X}^{T}\stackrel{\to }{y}\hfill \end{array}$

In the third step, we used the fact that the trace of a real number is just the real number; the fourth step used the fact that $\mathrm{tr}A=\mathrm{tr}{A}^{T}$ , and the fifth step used Equation  [link] with ${A}^{T}=\theta$ , $B={B}^{T}={X}^{T}X$ , and $C=I$ , and Equation  [link] . To minimize $J$ , we set its derivatives to zero, and obtain the normal equations :

${X}^{T}X\theta ={X}^{T}\stackrel{\to }{y}$

Thus, the value of $\theta$ that minimizes $J\left(\theta \right)$ is given in closed form by the equation

$\theta ={\left({X}^{T}X\right)}^{-1}{X}^{T}\stackrel{\to }{y}.$

## Probabilistic interpretation

When faced with a regression problem, why might linear regression, and specifically why might the least-squares cost function $J$ , be a reasonable choice? In this section, we will give a set of probabilistic assumptions, under which least-squares regressionis derived as a very natural algorithm.

Let us assume that the target variables and the inputs are related via the equation

${y}^{\left(i\right)}={\theta }^{T}{x}^{\left(i\right)}+{ϵ}^{\left(i\right)},$

where ${ϵ}^{\left(i\right)}$ is an error term that captures either unmodeled effects (such as if there are some features very pertinentto predicting housing price, but that we'd left out of the regression), or random noise. Let us further assume that the ${ϵ}^{\left(i\right)}$ are distributed IID (independently and identically distributed) accordingto a Gaussian distribution (also called a Normal distribution) with mean zero and some variance ${\sigma }^{2}$ . We can write this assumption as “ ${ϵ}^{\left(i\right)}\sim \mathcal{N}\left(0,{\sigma }^{2}\right)$ .” I.e., the density of ${ϵ}^{\left(i\right)}$ is given by

$p\left({ϵ}^{\left(i\right)}\right)=\frac{1}{\sqrt{2\pi }\sigma }exp\left(-,\frac{{\left({ϵ}^{\left(i\right)}\right)}^{2}}{2{\sigma }^{2}}\right).$

This implies that

$p\left({y}^{\left(i\right)}|{x}^{\left(i\right)};\theta \right)=\frac{1}{\sqrt{2\pi }\sigma }exp\left(-,\frac{{\left({y}^{\left(i\right)}-{\theta }^{T}{x}^{\left(i\right)}\right)}^{2}}{2{\sigma }^{2}}\right).$

The notation “ $p\left({y}^{\left(i\right)}|{x}^{\left(i\right)};\theta \right)$ ” indicates that this is the distribution of ${y}^{\left(i\right)}$ given ${x}^{\left(i\right)}$ and parameterized by $\theta$ . Note that we should not condition on $\theta$ (“ $p\left({y}^{\left(i\right)}|{x}^{\left(i\right)},\theta \right)$ ”), since $\theta$ is not a random variable. We can also write the distribution of ${y}^{\left(i\right)}$ as as ${y}^{\left(i\right)}\mid {x}^{\left(i\right)};\theta \sim \mathcal{N}\left({\theta }^{T}{x}^{\left(i\right)},{\sigma }^{2}\right)$ .

Given $X$ (the design matrix, which contains all the ${x}^{\left(i\right)}$ 's) and $\theta$ , what is the distribution of the ${y}^{\left(i\right)}$ 's? The probability of the data is given by $p\left(\stackrel{\to }{y}|X;\theta \right)$ . This quantity is typically viewed a function of $\stackrel{\to }{y}$ (and perhaps $X$ ), for a fixed value of $\theta$ . When we wish to explicitly view this as a function of $\theta$ , we will instead call it the likelihood function:

$L\left(\theta \right)=L\left(\theta ;X,\stackrel{\to }{y}\right)=p\left(\stackrel{\to }{y}|X;\theta \right).$

how can chip be made from sand
are nano particles real
yeah
Joseph
Hello, if I study Physics teacher in bachelor, can I study Nanotechnology in master?
no can't
Lohitha
where we get a research paper on Nano chemistry....?
nanopartical of organic/inorganic / physical chemistry , pdf / thesis / review
Ali
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
hey
Giriraj
Preparation and Applications of Nanomaterial for Drug Delivery
revolt
da
Application of nanotechnology in medicine
has a lot of application modern world
Kamaluddeen
yes
narayan
what is variations in raman spectra for nanomaterials
ya I also want to know the raman spectra
Bhagvanji
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
Got questions? Join the online conversation and get instant answers!