Hi Team,
While integrating in exercise 8 : nn_model, I’m getting a type error in the range of computing cost. Kindly help. Thanks.
TypeError : compute_cost() takes 2 positional arguments but 3 were given
Hi Team,
While integrating in exercise 8 : nn_model, I’m getting a type error in the range of computing cost. Kindly help. Thanks.
TypeError : compute_cost() takes 2 positional arguments but 3 were given
Hi @Rashmi , compute cost needs two arguments as the TypeError indicates, it also shows in the function that you have built in exercise 5. If you have indeed used two arguments within compute_cost(), a reason might be is that you have put a method in front of it which results python thinking you use three arguments, e.g. something like method.compute_cost(a,b) would give the same TypeError. Hope this helps.
Thanks @sjfischer ! Will Check and let you know!
Hi Stephanus,
I checked it all but couldn’t spot the error. Please help me. I am sending you the snapshot. Please forgive me for violating the honor code.
Thanks and regards,
Rashmi
Hi, @Rashmi. This is instructional for others so I will interject. What you posted is fine. Everyone has access to the the test cells of the notebooks, and the traceback log is very useful to the community for helping out in the discussion. Just the code in the ### Your code starts here … ### Your code ends here block is a violation.
While I am here, the TypeError clearly points out that that you have an extra argument in your compute_cost()
function. Examine the signature to the compute_cost
function (Exercise 5), and you will find your error, i.e. which argument that you have provided is superfluous.
Interesting. I would say that the error message is just about as clear as you could possibly hope for. But there is a problem here: notice that the comment is incorrect and Rashmi has just followed the comment. Yet another appropriate application of the old adage: “believe the code, not the comments”.
PS: we will file a bug report to get the comment corrected. (Update: this is Rashmi’s mistake. That comment is not present in the current version of the course. It must have been copied from an old notebook.)
I am still not able to spot it. The codes did fine and passed all the tests
in exercise 5th. I am sharing a snapshot (exercise 5th_compute_cost),
please have a look over it and let me know how I could complete this test,
as I am just stuck up over here for the past one week.
Thanks and regards,
Rashmi
Look at the way you call compute_cost when you call it from nn_model:
cost = compute_cost(A2, Y, parameters)
That is wrong. You have supplied three arguments to the function, but it only takes two. That is what the error message is clearly telling you. There is nothing wrong with your compute_cost function, as we can see from the earlier test result you show. The bug is in your nn_model logic.
Hello @paulinpaloalto, I just checked everything I could possibly do but its running the same output. I am not able to get the desired outcome. Please help me understand what should I do to clear the bug and to pass the test finally as I am failing after consistent efforts. (I am sharing you the snapshot again after redoing it as per your suggestion). Thanks & Regards!
Did you actually read what I said in my last reply? I gave you the answer. You need to remove the third argument when you call compute_cost: look at the definition of the function. You have not changed how you call compute_cost, which is why you are still getting this error. The comment that tells you to use three arguments is wrong (update: this incorrect comment was copied from a previous version of the course). I also mentioned that several replies ago.
Hello @Paul,
Sir, I will try that out. Thank you for your frequent response and rigorous support.
Thanks and Regards,
Rashmi
As I mentioned earlier, I will file a bug to get the erroneous comment fixed. In the meantime, the key point is that you have to believe the error message.
Update: see my later reply on this thread.
Yes sir.
Thanking you all.
Regards,
Rashmi
Thank you sir(s) @paulinpaloalto, @kenb and @sjfischer. It worked and I passed the test with full marks
@Rashmi: Actually it turns out that the incorrect comment you show is not in the current version of the Week 3 Planar Data Assignment notebook. It is only present in the old version of the course. So you must have copied the code from a notebook that was from the previous version of the course. Quite a few things changed when they issued new versions of all these courses in April 2021. If you are bringing saved work forward from before that date, you need to be very careful to study the differences between the old and new notebooks and not just blindly copy things over.
Hello @Paul, yes sir, I do agree that I did check a couple lines of code
from a previous discussion given on the same matter, when mine didn’t work
at that time and it might have caused some sort of complications over on
the python-based notebook that didn’t read my new codes later. I will
certainly be careful on this part.
Thanks and regards,
Rashmi