<< Chapter < Page Chapter >> Page >

Least squares revisited

Armed with the tools of matrix derivatives, let us now proceed to find in closed-form the value of θ that minimizes J ( θ ) . 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 = x 1 T x 2 T x m T .

Also, let y be the m -dimensional vector containing all the target values from the training set:

y = y 1 y 2 y m .

Now, since h θ ( x ( i ) ) = ( x ( i ) ) T θ , we can easily verify that

X θ - y = x 1 T θ x m T θ - y 1 y m = h θ x 1 - y 1 h θ x m - y m .

Thus, using the fact that for a vector z , we have that z T z = i z i 2 :

1 2 ( X θ - y ) T ( X θ - y ) = 1 2 i = 1 m ( h θ ( x ( i ) ) - y ( i ) ) 2 = J ( θ )

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

A T tr A B A T C = B T A T C T + B A T C

Hence,

θ J ( θ ) = θ 1 2 ( X θ - y ) T ( X θ - y ) = 1 2 θ θ T X T X θ - θ T X T y - y T X θ + y T y = 1 2 θ tr θ T X T X θ - θ T X T y - y T X θ + y T y = 1 2 θ tr θ T X T X θ - 2 tr y T X θ = 1 2 X T X θ + X T X θ - 2 X T y = X T X θ - X T y

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 tr A = tr A T , and the fifth step used Equation  [link] with A T = θ , 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 θ = X T y

Thus, the value of θ that minimizes J ( θ ) is given in closed form by the equation

θ = ( X T X ) - 1 X T 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 ( i ) = θ T x ( i ) + ϵ ( i ) ,

where ϵ ( i ) 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 ϵ ( i ) are distributed IID (independently and identically distributed) accordingto a Gaussian distribution (also called a Normal distribution) with mean zero and some variance σ 2 . We can write this assumption as “ ϵ ( i ) N ( 0 , σ 2 ) .” I.e., the density of ϵ ( i ) is given by

p ( ϵ ( i ) ) = 1 2 π σ exp - ( ϵ ( i ) ) 2 2 σ 2 .

This implies that

p ( y ( i ) | x ( i ) ; θ ) = 1 2 π σ exp - ( y ( i ) - θ T x ( i ) ) 2 2 σ 2 .

The notation “ p ( y ( i ) | x ( i ) ; θ ) ” indicates that this is the distribution of y ( i ) given x ( i ) and parameterized by θ . Note that we should not condition on θ (“ p ( y ( i ) | x ( i ) , θ ) ”), since θ is not a random variable. We can also write the distribution of y ( i ) as as y ( i ) x ( i ) ; θ N ( θ T x ( i ) , σ 2 ) .

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

L ( θ ) = L ( θ ; X , y ) = p ( y | X ; θ ) .

Questions & Answers

how can chip be made from sand
Eke Reply
are nano particles real
Missy Reply
yeah
Joseph
Hello, if I study Physics teacher in bachelor, can I study Nanotechnology in master?
Lale Reply
no can't
Lohitha
where we get a research paper on Nano chemistry....?
Maira Reply
nanopartical of organic/inorganic / physical chemistry , pdf / thesis / review
Ali
what are the products of Nano chemistry?
Maira Reply
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
Google
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
Hafiz Reply
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
Jyoti Reply
ya I also want to know the raman spectra
Bhagvanji
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
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
Brian Reply
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?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
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 ?
Bob Reply
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!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Machine learning. OpenStax CNX. Oct 14, 2013 Download for free at http://cnx.org/content/col11500/1.4
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Machine learning' conversation and receive update notifications?

Ask