LFD Book Forum  

Go Back   LFD Book Forum > Course Discussions > Online LFD course > Homework 4

Reply
 
Thread Tools Display Modes
  #1  
Old 04-28-2013, 05:19 PM
mvellon mvellon is offline
Junior Member
 
Join Date: Apr 2013
Posts: 9
Default *ANSWER* Stuck on #4

To calculate \bar{g} I generated several data sets each of two points where y=sin(pi*x). For each dataset, I generated a hypothesis (a slope a) that minimized the squared error for each of the two points. I did this by calculating the error as (ax_1-y_1)^2+(ax_2-y_2)^2, differentiating with respect to a, setting the result to zero and solving for a. This gave me a=(x_1y_1+x_2y_2)/(x_1^2+y_1^2). If I then average my per-dataset slopes (the a's), I get 1.42.

This seems wrong, not only as it's not an available choice () but also because it does not yield a smaller bias than, for example, .79.

I've seen suggestions to use linear regression to calculate the a's, but I don't think that's where I'm going wrong (not only that, but I'm not sure how to do the linear regression without an intercept term).
Reply With Quote
  #2  
Old 04-28-2013, 05:59 PM
yaser's Avatar
yaser yaser is offline
Caltech
 
Join Date: Aug 2009
Location: Pasadena, California, USA
Posts: 1,477
Default Re: *ANSWER* Stuck on #4

Quote:
Originally Posted by mvellon View Post
This seems wrong, not only as it's not an available choice () but also because it does not yield a smaller bias than, for example, .79.
Your procedure is correct. Just to address the above point without commenting on the correctness of your calculation, there is an available choice for your answer, and there is no requirement that the slope is less than 0.79.
__________________
Where everyone thinks alike, no one thinks very much
Reply With Quote
  #3  
Old 04-28-2013, 06:02 PM
marek marek is offline
Member
 
Join Date: Apr 2013
Posts: 31
Default Re: *ANSWER* Stuck on #4

For what it's worth, I think you're calculating 4 correctly. After 10^6 runs, my average a was 1.4301. It was unsettling to not see my answer among those listed, especially since the others depend on correctly interpreting this question. It would be nice to get further corroboration, simply because none of the above doesn't mean 1.43 was correct.

However, I believe your bias calculation may be off, as your conclusion is different than what I obtained despite having roughly the same a.
Reply With Quote
  #4  
Old 04-29-2013, 06:11 AM
jcmorales1564 jcmorales1564 is offline
Member
 
Join Date: Apr 2013
Posts: 12
Default Re: *ANSWER* Stuck on #4

I calculated it in two different ways and I get a consistent answer that is higher than answer [d] (0.79x). I am unsure as to how far away the answer must be to consider it answer [e] ("None of the Above")?

The difference between answers [c] and [d] is 0.34x. May I assume that if my answer is 1.13x or above (from 0.79x + 0.34x = 1.13x) then [e] "None of the above" is the correct answer (and viceversa)?

I need guidance as to how to determine, in general, how far is "far away" so that I can decide between answers [d] and [e].

Thank you.

Juan
Reply With Quote
  #5  
Old 04-29-2013, 09:21 AM
IsidroHidalgo IsidroHidalgo is offline
Member
 
Join Date: Apr 2013
Location: Toledo (Spain)
Posts: 28
Default Re: *ANSWER* Stuck on #4

Juan, after the derivative of the mean squarred error have you arrived to a=(x_1y_1+x_2y_2)/(x_1^2+x_2^2)?
If so, answer is IMO (I haven't send my answers) clearly upon 0.79
Good luck!
Isidro
Reply With Quote
  #6  
Old 04-29-2013, 09:27 AM
IsidroHidalgo IsidroHidalgo is offline
Member
 
Join Date: Apr 2013
Location: Toledo (Spain)
Posts: 28
Default Re: *ANSWER* Stuck on #4

Quote:
Originally Posted by mvellon View Post
To calculate \bar{g} I generated several data sets each of two points where y=sin(pi*x). For each dataset, I generated a hypothesis (a slope a) that minimized the squared error for each of the two points. I did this by calculating the error as (ax_1-y_1)^2+(ax_2-y_2)^2, differentiating with respect to a, setting the result to zero and solving for a. This gave me a=(x_1y_1+x_2y_2)/(x_1^2+y_1^2). If I then average my per-dataset slopes (the a's), I get 1.42.

This seems wrong, not only as it's not an available choice () but also because it does not yield a smaller bias than, for example, .79.

I've seen suggestions to use linear regression to calculate the a's, but I don't think that's where I'm going wrong (not only that, but I'm not sure how to do the linear regression without an intercept term).
I think you have a typo, is'n it? For me a=(x_1y_1+x_2y_2)/(x_1^2+x_2^2)
Reply With Quote
  #7  
Old 04-29-2013, 09:32 AM
Ziad Hatahet Ziad Hatahet is offline
Member
 
Join Date: Apr 2013
Location: San Francisco, CA
Posts: 23
Default Re: *ANSWER* Stuck on #4

Quote:
Originally Posted by IsidroHidalgo View Post
I think you have a typo, is'n it? For me a=(x_1y_1+x_2y_2)/(x_1^2+x_2^2)
Yes, that's what I got too. So you're saying that with using this formula, you're getting 0.79, and not 1.42 as mentioned in a couple of other threads?
Reply With Quote
  #8  
Old 04-29-2013, 09:49 AM
IsidroHidalgo IsidroHidalgo is offline
Member
 
Join Date: Apr 2013
Location: Toledo (Spain)
Posts: 28
Default Re: *ANSWER* Stuck on #4

Not at all. Using this a I obtain 1.42...
Reply With Quote
  #9  
Old 04-29-2013, 10:54 AM
yaser's Avatar
yaser yaser is offline
Caltech
 
Join Date: Aug 2009
Location: Pasadena, California, USA
Posts: 1,477
Default Re: *ANSWER* Stuck on #4

Quote:
Originally Posted by jcmorales1564 View Post
I am unsure as to how far away the answer must be to consider it answer [e] ("None of the Above")?
Your answer should agree with the given answer to two-decimal-digit accuracy as stated in the problem, or else be considered "none of the above."
__________________
Where everyone thinks alike, no one thinks very much
Reply With Quote
  #10  
Old 04-29-2013, 11:03 AM
jcmorales1564 jcmorales1564 is offline
Member
 
Join Date: Apr 2013
Posts: 12
Default Re: *ANSWER* Stuck on #4

I also obtain 1.42 with the formula you mention which is based on deriving WRT "a" and equalling to zero to minimize. I also calculated 1.4 by finding the "a" for each value of x1 and x2 and then selecting the "a" associated with the smaller mean squared error.

The answer (a = 1.4), which is higher than the case discussed in class, makes sense to me because the line is forced to pass through zero. It can only rotate about the origin. It removes the translational degree of freedom that would otherwise be available when the intercept is included (y = ax + b). In that latter case any two points are used to create the line (the case discussed in class), and there is a high probability of obtaining many more cases with slope close to zero so I would expect "a" to be lower when using y=ax + b (after calculating the average of many cases). It also makes sense that b tends to zero.

Supposing 1.42 is the correct value, should it be [d] or [e]?

To "d", or not to "d", that is the question
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 02:43 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.