LFD Book Forum (http://book.caltech.edu/bookforum/index.php)
-   Homework 5 (http://book.caltech.edu/bookforum/forumdisplay.php?f=134)
-   -   Basic logistic regression question (http://book.caltech.edu/bookforum/showthread.php?t=4261)

 arcticblue 05-04-2013 04:09 AM

Basic logistic regression question

From lecture 9 page 23 of the slides there is an algorithm of how to implement logistic regression. In step 3 it explains how to compute the gradient. Is the E-in value actually a vector or is it a single number? If it's a single number then the weight would be the same for every value in the weight vector so it seems like E-in is a vector. Is my understanding correct?

And if it's a vector then I'm a little unclear on how to compute the values. Each training point has two values x1 and x2 and an outcome y. So to calculate E-in do I just use x1 and weight1 to find the first value and then use x2 and weight2 to find the second value?

Hopefully the above makes sense, I seem to be struggling with something that seems like it should be pretty simple.

 yaser 05-04-2013 10:10 AM

Re: Basic logistic regression question

Quote:
 Originally Posted by arcticblue (Post 10694) From lecture 9 page 23 of the slides there is an algorithm of how to implement logistic regression. In step 3 it explains how to compute the gradient. Is the E-in value actually a vector or is it a single number? If it's a single number then the weight would be the same for every value in the weight vector so it seems like E-in is a vector. Is my understanding correct?
is a scalar quantity whose value depends on the entire vector of weights . Step 3 computes the gradient, which is a vector of derivatives of with respect to each of those weights, so each component of the gradient vector is the derivative with respect to a different weight

 arcticblue 05-04-2013 08:27 PM

Re: Basic logistic regression question

Okay I think I see how that works but I'm still struggling to understand Q8. In the question I set the weights to 0. Then the first time through the loop I will calculate the gradient of E_in using the formula in step 3. Because w is all zeros the denominator will end up as 1+ e^0 == 2. The numerator can at most be +/-1/ So the biggest change in gradient is +/-0.5 for each weight.

Then in step 4 I update the weights
w(1) = 0,0,0 - 0.01(0.5,0.5,0.5)
w(1) = (0.005,0.005,0.005)

Now the question states stop the algorithm when ||w(t-1) and w(t)|| < 0.01. So:
sqrt((0-0.005)^2+(0-0.005)^2+(0-0.005)^2) = 0.008
So based on the values above the algorithm will stop after the first iteration because the difference in weights is < 0.01.

Have I misunderstood the gradient of E_in formula? Or am I calculating my error incorrectly? I've tried using batch gradient descent and see the above results (I have 100 data points but the error still ends up less than 0.01.) I've also tried stochastic gradient descent and have similar problems.

I've watched lecture 9 a couple of times now and seem to understand how the algorithm works but I guess my understanding isn't complete.

Any suggestions would be most appreciated.

 yaser 05-04-2013 09:38 PM

Re: Basic logistic regression question

Quote:
 Originally Posted by arcticblue (Post 10702) Now the question states stop the algorithm when ||w(t-1) and w(t)|| < 0.01.
The values are calculated at the end of an epoch per the preamble to Question 8, so you need to run through all the examples first to get to the end of the epoch.

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