Failure due to nonuser implementation error in C1_W3_Logistic_Regression final lab?

I’m unable to successfully complete MLS Course 1 due to perhaps an issue that appears to stem from non user implementation error in the final lab. I’ve completed the lab and all unit tests pass. However, when the lab is graded, the following issue is noted by grader:

Cell #18. Can't compile the student's code. Error: ValueError('x and y must have same first dimension, but have shapes (2,) and (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2)')

It looks like the error stems from this cell in the lab ( image below ). My understanding is students don’t touch the cell responsible for that operation. Help please

I don’t have access to that exercise, but if you trace from the exception backwards through the call stack, it looks to me like you get to the variables w and b that are passed in to plot_decision_boundary(). I’d take a close look at their shapes and see if they aren’t directly related to the shapes in the error message. I’m particularly suspicious of b but it’s just a hunch.

Thanks. I followed your advice and it appears everything in that execution graph is locked. I can’t change or edit that cell at all. This is the only barrier to earning my first certificate in the specialization.

Hello @Jesse_B,

The ungraded cells are locked to prevent unexpected changes that can cause troubles to assignment submission. We don’t need to change anything in ungraded cells to pass the assignment, but we do want to trace back to the source of the problem. This is going to take a few posts but if you will stay with me, hopefully we can find out the problem soon.

First, the error message talked about the shape of y which is a long list of ones plus a two at the end. This is abnormal. Moreover, this part of the traceback said the y is computed using w and b:

image

So if either w or b (or plot_x) has a problem, it can propagate to plot_y, then y, and finally get you that error message.

Now I need you to add a code cell like the following. Then run all the code cells from the beginning up to that added code cell, and share with me what it prints:

image

You may copy the code from here:

print(w.shape, b.shape, X_train.shape, y_train.shape)

Note that, before submission, you will need to remove the added cell. Therefore, this cell is added only temporarily for investigations.

Raymond

PS: to add a cell there, single-click on the description right above, then click the " + " button on the menu bar.

Thank you @rmwkwok .

I applied a new cell with the code you provided. Here’s the print out:

(2,) (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) (100, 2) (100,)

I’m also attaching a screenshot of the printout:

Thanks for coming to the rescue!

so the trouble is with the b shape? :thinking:

I can’t tell which param is at fault but definitely a mismatch in dimensions. Based on my limited knowledge of Numpy, it appears b.shape is deeply nested structure with a single value while w.shape is a 2 dimensional structure. The code expects the shape[1] for both w and b to be identical.

Unfortunately I can’t effect w and b since they’re returned from gradient_descent function which is locked.

I’ve reported the bug but do you have further ideas on how I can fix? Thank you

Hello @jesse_B,

Again, the ungraded cells are locked because they are not supposed to be changed… I said this would take a few posts, so let’s continue the investigations…

The w and b that you were printing were, ofcourse, from gradient_descent which processed them with dj_dw and dj_db.

And, dj_dw and dj_db are returned by gradient_function (alias for compute_gradient) which is the exercise 3. To check whether exercise 3 is producing expected results, please replace the content of the added cell with the following, and run it like I said last time:

You may copy the code from here:

# print(w.shape, b.shape, X_train.shape, y_train.shape)
intial_w = 0.01 * (np.random.rand(2).reshape(-1,1) - 0.5)
initial_b = -8
_dj_db, _dj_dw = compute_gradient(X_train, y_train, intial_w, initial_b, lambda_=0)
print(intial_w.shape, initial_b)
print(_dj_dw.shape, _dj_db)

Cheers,
Raymond

PS: as @ai_curious said, the shape for of b is worrying. My post seems to be focusing on w but it actually is about both w and b.

Hi Raymond,

Thank you for your persistence. I was away for a few days and now finally back. I really want to earn this certificate :slight_smile:

Adding the cell per your response, here’s the output:

(2, 1) -8
(2, 1) [[-0.59964372]]

My reading may be imperfect but the output for _dj_dw is 2x1 and _dj_db is 1x1. Would you say everything is OK at this point? The next step is to check the cost function?
Thank you

Thanks @Jesse_B! Your dj_db is [[-0.59952583]] where as mine is [-0.59952583]. I think there is something wrong in computing the dj_db in compute_gradient. I understand that you have passed some tests to come to this stage, but it must be something that the previous public test can’t catch. Now I suggest you to:

  1. remove the added code cell (since we don’t need it now, but we don’t want to forget to remove it later)
  2. beneath the exercise cell for compute_gradient, add a new code cell, and paste the following which is just what we had used last time:
# This cell should be removed after investigation
intial_w = 0.01 * (np.random.rand(2).reshape(-1,1) - 0.5)
initial_b = -8
_dj_db, _dj_dw = compute_gradient(X_train, y_train, intial_w, initial_b, lambda_=0)
print(intial_w.shape, initial_b)
print(_dj_dw.shape, _dj_db)
  1. Since debugging is part of the assignment, and I think adding the cell there helps you debug. Your goal would be to pass the added cell, and all subsequent public test.

Good luck!
Raymond