Output correct but Public Test says incorrect


When I ran ‘def cofi_cost_func()’

Without the regularization code I got 13.67. This was the expected answer.

With the regularization code I got 28.09. This was the expected answer. So at this point ‘Public Test’ should work correctly.

When I run the ‘Public Test’ it stated
‘AssertionError: Wrong value. Expected 27, got 32.901542053418716. Check the regularization term’.

My code block was
{moderator edit: code removed}

This is not necessarily true. Your code is tested with several different sets of data and conditions. It’s expected to pass all of them.

When an assert says your code returned the wrong value, it indicates a defect in your code.

Please do not post your code on the forum. That’s not allowed by the Code of Conduct. If a mentor needs to see your code, we’ll contact you with instructions.

Yes, as Tom says, just passing one test does not mean your code is fully correct. If you pass one test, but fail others, that means your code is not general in some fashion. Ways that could happen would be to hard-code assumptions about the dimensions of objects to match that one particular test case. Or referencing global variables within the local scope of your function.

These courses have been in use for a while now and if this test was fundamentally broken we would have heard about it by now. So this means you have some debugging to do. :nerd_face:

Of course it’s always possible that you’ve discovered some new wrinkle, but you need to do some debugging first. One thing to note is that you can actually look at how the public tests work. They are in a file that is imported by the notebook. Just click “File → Open” and find the file.

Actually we can see the bug in the code you posted: you are referencing the variables X_r and W_r which must be globals, since we don’t see them defined in the function. I am not a mentor for this course, so I haven’t actually worked this exercise, but this is just basic python scoping. My guess is you should be referencing X and W there.

This is exactly what I meant by the code not being “general”. It works in that one test case, if X_r is the actual value that happens to be passed as the argument X (and likewise for W). But what happens if the public test passes different variables?

That is hilarious and thanks for the find.

Before I do any coding in the coursea assessments I do the coding in google colab. This is to ensure that I understand what I am doing. I obviously copied and pasted, as I was a bit lazy, instead of rewriting the code with the variables pertaining to that function.

It was driving me crazy. :blush:

Programming can be frustrating because it’s the intersection of high level concepts and the absolutely most nitty gritty details. You have understand all these big ideas, but then one comma in the wrong place or the difference between ; and : blows the whole thing up. :scream_cat:

But the rumor is that ChatGPT can be a pretty good programmer. That may save us some work, but we also may end up out of a job. It would be good news if we could just do the conceptual stuff and leave the nitty gritty stuff to ChatGPT, but the problem is that the models only get better over time. It will be interesting to see how it all plays out. I have been meaning to go take some of the Short Courses here about LLMs and then try using ChatGPT, but haven’t had time yet.

I use ChatGPT a lot and find that you still need to know what you are doing else it can get things wrong. Another AI LLM to use is https://pi.ai/talk.

Thanks for the link. I hope to get some time to explore this pretty soon.