reset password
Author Message
lmann2
Posts: 156
Posted 18:03 Feb 11, 2016 |

Hi there,

  Mark has mentioned in class several times that we can we can create a cost function without a loop, but I see no way to do this (image our parameters are is the numpy array of features, our vector of y values and a vector of theta values) without a outer loop.   

rkmx52
Posts: 23
Posted 20:53 Feb 11, 2016 |

It's doable if you make use of NumPy matrix multiplication, transpose, etc.

lmann2
Posts: 156
Posted 10:23 Feb 13, 2016 |

Well, I was refering to the math, but I figured out this implementation after way too many hours nosing around documentation so i'll explain as best I can here in hopes that it helps someone out.  

We have a 415X10 (remember that we are adding a single column of ones to our matrix for the theta nought value) and we're going to find the dot product of this matrix with a vector of random theta values 1x10 (we're using the cost function later on to check on our gradient function as it converges or that's how I now understand the purpose of this).  The problem is we can't dot them at they are, but if transpose theta we get 415x10 dot 10x1 which produces a single 415x1 vector of values that calulates our polynomial (theta_0 + (theta_1)(x_1) + ... + (theta_n)(x_n).  At this point you should have pulled out your y values during the data munging process and with the result vector of the previous calculation you can easily substract y from the results.  After this operation all you need to do is sum up the vector that returns from substracting results from your y (or actual) values.  With the sum you can then perform on outer operations of the cost function (that is outside the summation step).

The only thing mathmatically that confuses me is whether or not to scale y as we're trying to distance for the actual y values....I think we have too...not sure about that.

rkmx52
Posts: 23
Posted 14:23 Feb 13, 2016 |

From what I understand, we are not supposed to scale y. As it is "feature" scaling.