C1_W2 Linear Regression : Compute Cost Error

When creating a post, please add:

  • Week # must be added in the tags option of the post.
  • Link to the classroom item you are referring to:
  • Description (include relevant info but please do not post solution code or your entire notebook)

Hi, I’ve been stuck on this Test for a couple of weeks now.
I’m receiving the Error below and I can’t seem to figure where I got it all wrong. Please assist.

<class ‘NoneType’>

TypeError Traceback (most recent call last)
5 cost = compute_cost(x_train, y_train, initial_w, initial_b)
6 print(type(cost))
----> 7 print(f’Cost at initial w: {cost:.3f}')
9 # Public tests

TypeError: unsupported format string passed to NoneType.format

{mentor edit: code removed}

1 Like

A few tips:

  1. Please do not 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.

  2. Your code has some errors. Note that you’re computing a “cost” value inside the for-loop, but you don’t use it in computing total_cost. The way your code is written, the cost_sum variable is always 0.

  3. Before you can run a test, you have to run all of the cells before it in the notebook. You have to do this every time you open the notebook. Did you run the cell with the compute_cost() function definition before you ran cell [10] that contains the test?

1 Like

Thank you.
I always run all cells from the top. I think there could be an error with my code but I cannot point where exactly I got it wrong

1 Like

I’m going to guess that there is a problem in your notebook in one of the cells just before the compute_cost() cell, such that the function isn’t running correctly.

Or, you may have an indentation problem, and the return statement in compute_cost() isn’t being run correctly.

Solved. I had indentation issue and 2 “compute_cost” statements in the code. I removed one and the problem was fixed.

Thank you for you assistance

1 Like