MLS Week 3 Practice Lab

I’m not getting the desired output in exercise. My cost for the initial parameter w is coming in at 0.007 instead of the desired 0.693. Can anyone proffer any advice?

Hi @Kingsley_Okiwelu,

I suppose you are asking about this exercise test:

Screenshot from 2022-09-10 22-26-36

This test assigns all the weights and the bias values to be 0, and compute the cost of such setting. My suggestion is for you to check your code by:

  1. print the X and y of the first sample by print(X_train[0], y_train[0])
  2. assume all weights and bias be zeros, put these and the sample X, y values into the cost equation shown in the exercise 2 description so you know the correct cost value to expect for
  3. plug in the value to your function implementation and calculate what the cost would be following your code, you can do this check with pencil and paper

The cost in step 2 & 3 should be the same, and if not, your calculation should give you some ideas of where goes wrong. This is how we usually debug our own code, and code debugging is an important skill.

Raymond

1 Like

Hi. I have tried to implement your suggestion but it seems my parameters should be OK because my expected g(z) with w and b set to 0 should be 0.5 which indicates that my compute_cost is working properly. However I’m still arriving at 0.007 instead of 0.693 for my minimized cost function. Can you assist me in debugging my code?

Hey @Kingsley_Okiwelu,

My suggestion asks you to try the zeroth sample, and if that passes, please then try the first sample. There got to be a sample that won’t pass and it shouldn’t be more than 2 or 3 tries. If a single sample doesn’t reveal the problem, then use the first two samples together.

There is no way better than this in debugging your code. I will only ask/suggest for the same.

Raymond

For example,

Screenshot from 2022-09-12 02-38-23

Since w’s and b are zeros, g(z) should be 0.5 as you said, but that is not the end, because it’s just g(z), and g(z) is NOT the cost. If you read the exercise’s description again, you find the way to calculate the cost for a single sample, or the loss function, which is the 2nd equation in my screenshot below:

Plugging f_{w,b}(x) as 0.5 and y as 0 will give you a loss of -1 \times \log{(0.5)} = -0.693. Your response above clearly didn’t include this. Did you implement the loss formula into your code? If not, you need it.

Also the hint beneath the exercise (you need to click the green “Clicks for hints” button to see the hints) also provided you the skeleton and you need only to follow that. In the bottom of the skeleton, there are also some blue buttons to click into for more hints.