Week 3 lab question 2

I am getting this error. pls help

m, n = X_train.shape

Compute and display cost with w initialized to zeroes

initial_w = np.zeros(n)
initial_b = 0.
cost = compute_cost(X_train, y_train, initial_w, initial_b)
print(‘Cost at initial w (zeros): {:.3f}’.format(cost))

TypeError Traceback (most recent call last)
in
5 initial_b = 0.
6 cost = compute_cost(X_train, y_train, initial_w, initial_b)
----> 7 print(‘Cost at initial w (zeros): {:.3f}’.format(cost))

TypeError: unsupported format string passed to function.format

First I’ll move your post to the correct forum area. You put it in C1 Week 2, but your subject says Week 3.

Notes:

  • Be sure that you run all of the cells in the notebook starting from the top. Do this every time you open the notebook to start working.

  • Are you running the notebook in Coursera Labs, or are you using another tool?

still it’s showing the same error
I am using the coursera labs

Hello @SMRUTI_SARITA,

Let’s look at the error message:

----> 7 print(‘Cost at initial w (zeros): {:.3f}’.format(cost))

TypeError: unsupported format string passed to function.format

function.format indicates that your cost is a function but that is problematic because we can’t format a function into a string of 3 decimal places. We can only do this for a number, not a function. Look at the following examples and you should be able to tell the difference.

image

Now, the cost is supposed to be a floating-point number, but yours is a function, so you need to check your code to find out why your compute_cost function isn’t returning a number.

Cheers,
Raymond