Week 3 Final Getting Strange Results..I am not a programmer!

Hi,

I am getting very strange results (a huge number) on my exercise 2 cost. Can someone help?

I took this course to get an introduction and, unfortunately, am not a programmer (I am a technical writer)…So far I was able to go through all of the exercises and follow more or less. Andrew in his video was encouraging (I got the message that I didn’t have to worry about knowing Python). But now I have doubts. Can someone help? I think it would have been a great idea to have some kind of TA /discussion sessions along with this course.

@Jiri_Weiss I believe it could be the wrong implementation of the formula to compute the cost. You may like to paste the snippet so that we can shed some insights and also not breach the honor code indirectly :blush:

Hi Alan, thanks so much for your offer to help. Here is the code. Frankly, I don’t have much of an idea what I am doing :hot_face:

### START CODE HERE ###

# mentor edit: code removed

### END CODE HERE ### 

return total_cost

what I get is some huuuge number when I check the implementation in the next section

@Jiri_Weiss Maybe you can use the one line np.dot to compute z before passing into the sigmoid function. It much cleaner and efficient compare to using a for loop to compute dot product which I feel is messy and prone to logic error. Give it a shot and see if it help before troubleshooting the rest of the code . :blush:

All of the DLAI MLS courses assume that students already have basic skills in Python programming.

So I recommend you pause what you’re doing and attend an introductory Python course.

In the future, please don’t 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.

The course instructions and the hints in the notebook recommend using for-loops.

You are correct that dot products are a good idea, but that’s not consistent with the way the material is taught in this course.

1 Like

My mistake for asking on the snippet. Will be mindful on this . Thanks for reminding

@Jiri_Weiss, I think the essential problem in your code is here:
image

What this code does is add loss_sum twice, because it’s using both “add and update” the += operator, and is also adding loss to the result.

So you could use either of these methods (they are equivalent), but don’t use both at the same time:

loss_sum += loss
…or…
loss_sum = loss_sum + loss