Week 2 practice lab: Linear regression. Assertion error

Hi,
On exercice 1, after adding the code:

### START CODE HERE ###
# mentor edit: code removed
### END CODE HERE ###

I tried to check if the implementation was correct so I tried to run the test code below but it displays:
<class ‘float’>
Cost at initial w: 0.000

AssertionError Traceback (most recent call last)
in
9 # Public tests
10 from public_tests import *
—> 11 compute_cost_test(compute_cost)

~/work/public_tests.py in compute_cost_test(target)
17 initial_b = 1.0
18 cost = target(x, y, initial_w, initial_b)
—> 19 assert cost == 2, f"Case 2: Cost must be 2 but got {cost}"
20
21 # print(“Using X with shape (5, 1)”)

AssertionError: Case 2: Cost must be 2 but got 0.0

What can I do?
Thank’s

  1. Please do not share your code on the forum. That’s not allowed by the Code of Conduct. Posting your error messages is a better method. If a mentor needs to see your code, we’ll contact you with instructions.

  2. Hint: Does your code ever update the value in cost_sum?

1 Like
  1. OK, sorry for that.
  2. No it doesn’t.

Were you able to fix the issue?

Yes, thank you.

1 Like

Hi all, I need help with the 1st assignment for C1 W2. I am having trouble navigating the datasets in jupyter notebook. Please help. Thanks

What exactly do you mean by “navigating the datasets”? I don’t think any navigation is necessary.

If you follow along in the instructions in the notebook, and come to something you don’t understand or doesn’t work, please post a screen capture image of the issue.

Note that you should not post an image of your code.

having a problem with cost function and receive this error


Before your code enters the for-loop, did you give cost_sum an initial value?

yes, i set cost and cost_sum and total_cost = 0. the instructions state " # You need to return this variable correctly" ??

got it, needed to go back and rerun each section independently, damn

1 Like

Always re-run every cell that you modify. It isn’t automatic.

i am running the same code as the optional lab for week 3 excercise 3 and getting this error File “”, line 24
err_i = f_wb_i - y[i]
^
SyntaxError: invalid syntax.

The syntax error is somewhere prior to the first character in the “err_i = …” line.

Which optional lab exactly are you using as a reference? Week 3 has nine optional labs.

Your thread title uses the Week 2 tag, by which I assume you’re working on the linear regression assignment, which does not use sigmoid().

Update: It appears you’re using code from optional lab C1_W3_Lab06.

The only optional lab related to computing gradients for logistic regression: Optional lab: Gradient descent for logistic regression

If you’re working on the Week 2 graded assignment (as your thread title indicates), you should not be using code that includes sigmoid().

The syntax error may be due to copy-and-paste that includes some non-printable character. Try deleting the indentation from that line, and re-insert it.

Hi I’m getting this error. It seems that I’m just getting a different answer than expected, but I don’t see anything obviously wrong with my code. Thanks for the help.


AssertionError Traceback (most recent call last)
in
9 # Public tests
10 from public_tests import *
—> 11 compute_cost_test(compute_cost)

~/work/public_tests.py in compute_cost_test(target)
17 initial_b = 1.0
18 cost = target(x, y, initial_w, initial_b)
—> 19 assert cost == 2, f"Case 2: Cost must be 2 but got {cost}"
20
21 # print(“Using X with shape (5, 1)”)

AssertionError: Case 2: Cost must be 2 but got 1.5

It would seem there is an error in your code.

The most common problems with this assignment is incorrect indentation. This changes the flow of order of operations of the code.

The next most common problem is due to using global variables inside a function, instead of using the local function areguments.

Hi. Thanks; it looks like I had an indexing issue.

That’s good news!