Code for Andrew Ng's Machine Learning: Advanced Learning Algorithms Is Failing Even Though It Should Work

I tried doing the code for Week 3 of the second unit of Andrew Ng’s Machine Learning course, and for the end practice lab for the first assignment, I put in the equation I should have put in and it failed with an error. I then looked at the hint, which turned out to be the solution, and it had the same logic as my code, which still failed even when I put the solution in line by line. I have ran the previous boxes of code, but it is still failing. Is this a problem anyone else has had at all, and how did you solve it?

Are you sure that you clicked “Shift-Enter” on the cell containing the actual code before you ran the test? Notice that your code prints the incorrect value 0.0.

If you just type new code and then call the function again, it runs the old code.

The other easy way to make sure that WYSIWYG is:

Kernel -> Restart and Clear Output
Save
Cell -> Run All

Does the test case still fail when you do that?

Here’s another recent thread which discusses this point about the code being not what you are running and shows an experiment to demonstrate how this works.

In addition to Mentor Paul’s thoughts:

In your line that computes err_i, you have an outer set of parenthesis which might make the grader unhappy later.