Problem 2: In the Supervised Machine Learning Week 3 practice lab on Logistic Regression, in cells 27-29, we are told to just run the code without altering it, and even that gives incorrect results. The expected output does not converge, and the boundary line in cell 29 is very far from where it should be.
Expected result:
Actual result:
Remember, this is the code supplied by Coursera, with no changes by the user.
I have attached my Jupiter notebook
{moderator edit: code removed}
As I replied in the other thread, I implemented the code EXACTLY as directed in the hints. And my code PASSED the tests. So the problem is not in my code, there is something in their implementation that is wrong.
Make sure you do not rename your notebook. That will make the grader unhappy.
Python is extremely picky about how you indent your code.
So, your compute_gradient() function does not return the correct values for dj_db and dj_dw, for either test. See your results of Cell [14], for example. Those aren’t the correct results.
None of the rest of the assignment is going to work correctly until you fix that.
Here are some things to check:
does your sigmoid() function pass its tests?
did you use the sigmoid() function when you computed f_wb?
did you use the hints for the compute_gradient() function?
In that image, I’ve drawn arrows at the three lines you need to complete. There are hints for all three.
Note that if you’re good at matrix algebra, there is a much simpler way to compute the gradients, which doesn’t require complicated for-loops. You only need to use your sigmoid() function, along with np.dot() function a couple of times, and np.sum() once.
It’s only three lines of code.
The first one computes f_wb.
The next two lines come straight from the matrix implementations of these equations:
One further hint about indentation:
Here is an area that students often overlook. Check the indentation in this area very carefully. The division by m should only happen once - it is outside of the for-loop over ‘i’, and just before the return statement.
OK, thanks. Yes, it was the fussy indentation in Python. The final calculations of dj_dw and
dj_db were within the for i in range(m) loop. Once I moved them out, everything worked fine. Thank you.