![]() |
*ANSWER* HW5 Q8/9 - Help with R code
Hi, can anybody send me their R code for Q 8/9 or look at mine (appended below)? My gradient descent never runs for more than 1 epoch. I can't figure out what I'm doing wrong, I've pored over my code for so long I'm feeling cross-eyed
# Learning from Data HW5 (items 8 and 9) # Logistic Regression with Stochastic Gradient Descent nIter = 100; nIn = 100; nOut = 10000; eta = 0.01; eOut = rep(NA, nIter); nEpochs = rep(NA, nIter); set.seed(123); for (i in (1:nIter)) { # Initialization of f(x) and of matching In-sample nEpoch = nEpoch +1; }} # E(Eout) avgEOut = mean(eOut); # E(NEpoch) avgNEpoch = mean(nEpochs); |
Re: *ANSWER* HW5 Q8/9 - Help with R code
Hi Catherine,
It would help if you can wrap your code up in the code tags. The tags can be found with the other formatting options when posting a message on the forum. This will make it easier for us to read and remove the sad face, although I thought it was appropriate. |
Re: *ANSWER* HW5 Q8/9 - Help with R code
Sorry, I hadn't noticed the advanced editing option. First time I'm posting something to the forum.
|
Re: *ANSWER* HW5 Q8/9 - Help with R code
Quote:
|
Re: *ANSWER* HW5 Q8/9 - Help with R code
I think the following bit of code has a bug. You are updating w and w0 every time through the loop and then comparing the two w's at the end. I believe you should be comparing the value of w from before the loop to the value of w at the end of the loop.
So the first time you have w=[0,0,0] then you loop through all points updating the weight. Then after that you compare w=[0,0,0] with weight you have at the end of the loop. Then you use the updated weight as the initial weight for the next time through the loop. Code:
for (j in permuted.ind) { |
Re: *ANSWER* HW5 Q8/9 - Help with R code
Good spotting! Thank you so much arcticblue! I had simply misread the definition of the exit condition :)
|
Re: *ANSWER* HW5 Q8/9 - Help with R code
Hello all:
I answered questions 8 and 9 incorrectly. My R code ran, but it is giving wrong values. Here it is: Code:
#Q8 |
Re: *ANSWER* HW5 Q8/9 - Help with R code
Yes, I now get average number of epochs = 340.17 and average error out = 0.1036295 after correcting the exit condition for the gradient descent:
Code:
# Gradient descent |
Re: *ANSWER* HW5 Q8/9 - Help with R code
OOps! Thanks for pointing that out, catherine! That's how I blew away 2 points on that quiz!
|
All times are GMT -7. The time now is 06:14 AM. |
Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2021, 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.