LFD Book Forum  

Go Back   LFD Book Forum > General > General Discussion of Machine Learning

Reply
 
Thread Tools Display Modes
  #1  
Old 07-25-2012, 01:59 PM
lorddoskias lorddoskias is offline
Junior Member
 
Join Date: Jul 2012
Posts: 9
Default Normal equation in linear regression

From coursera's ML course I've known that the normal equation is calculated as follows:

pinv((X'*X))*X'*Y; (octave code) but apparently this is equivalent to just pinv(X)*Y;

Can anyone explain why this is the case?
Reply With Quote
  #2  
Old 07-25-2012, 02:12 PM
yaser's Avatar
yaser yaser is offline
Caltech
 
Join Date: Aug 2009
Location: Pasadena, California, USA
Posts: 1,477
Default Re: Normal equation in linear regression

Quote:
Originally Posted by lorddoskias View Post
pinv((X'*X))*X'*Y; (octave code) but apparently this is equivalent to just pinv(X)*Y;

Can anyone explain why this is the case?
pinv is already the pseudo inverse function. When applied to an invertible matrix (in this case X'*X), it returns the regular inverse.
__________________
Where everyone thinks alike, no one thinks very much
Reply With Quote
  #3  
Old 09-18-2012, 11:06 PM
Daniel Daniel is offline
Junior Member
 
Join Date: Jun 2012
Posts: 4
Default Re: Normal equation in linear regression

Dr. Ng derived the Normal Equation in class, see Lecture 4-6 and he also cautioned about the case where X'*X is non-invertible which meant that there were redundant features (linearly dependent) or too many features (m <= n).

Daniel
Reply With Quote
  #4  
Old 09-20-2012, 03:24 AM
magdon's Avatar
magdon magdon is offline
RPI
 
Join Date: Aug 2009
Location: Troy, NY, USA.
Posts: 595
Default Re: Normal equation in linear regression

Just a small correction on notation. The normal equations for linear regression are

X^TX w = X^T y.

The solution to the normal equations (for w) is given by the formula that you mention, and indeed the two solutions are equivalent. A proof of this fact is using the singular value decomposition:

X=U\Sigma V^T and X^\dagger=V\Sigma^\dagger U^T

where U^TU=I and V^TV=I. So,

(X^TX)^\dagger X^T=(V\Sigma U^TU\Sigma V^T)^\dagger V\Sigma U^T=V(\Sigma^2)^\dagger V^T V\Sigma U^T=V\Sigma^\dagger U^T=X^\dagger

Quote:
Originally Posted by lorddoskias View Post
From coursera's ML course I've known that the normal equation is calculated as follows:

pinv((X'*X))*X'*Y; (octave code) but apparently this is equivalent to just pinv(X)*Y;

Can anyone explain why this is the case?
__________________
Have faith in probability
Reply With Quote
  #5  
Old 09-25-2012, 12:25 AM
broken857 broken857 is offline
Junior Member
 
Join Date: Sep 2012
Posts: 1
Default Re: Normal equation in linear regression

Thanks you all for useful input. We have some reading to do... :-)
__________________
williamjhone
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:11 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
The contents of this forum are to be used ONLY by readers of the Learning From Data book by Yaser S. Abu-Mostafa, Malik Magdon-Ismail, and Hsuan-Tien Lin, and participants in the Learning From Data MOOC by Yaser S. Abu-Mostafa. No part of these contents is to be communicated or made accessible to ANY other person or entity.