Supervised Learning: Week 3 : Classification # UNQ_C2


im getting error here can anyone help to slove me?

HI @26_Komal_Kamble ,

Python uses indentation to structure code block. Looking at your code, the indentation is incorrect. The first ‘For’ loop statement should be indented, following the indentation as loss_sum = 0.

Hello @26_Komal_Kamble,

This is a 5-minute post quickly goes through how to indent.

Raymond


I’m getting this error can u help me to slove this?

Hello @26_Komal_Kamble,

We will not solve it for you, but we can make suggestions so that you can work through it yourself. Now, I see 3 problems from your screenshots.

  1. np is not defined.
    Screenshot_20230127_024209

  2. some code are colored RED.
    Screenshot_20230127_024212

  3. Submission error.
    Screenshot_20230127_024215

Now, I need you to fix them one by one.

  1. There should be this line import numpy as np in the first code cell of your notebook. Is it there? If it is there, then the error message indicates that you had not run the first code cell. On the menu bar of the jupyter notebook, please click “Kernel” > “Restart”, and run the notebook from the first cell down. This error message should not come up again.

  2. They are colored RED because the indentation is not proper. I suggest you to open two browser windows and put them side by side. On the left, go to this post, and on the right, it is your notebook. The post tells you how to “reset” the indentation, and after that, re-indent all the lines properly with the “Tab” key on your keyboard. Please do read through my post on how to ident, and if you follow my guide, you can finish this in less than 2 minutes. After you have properly indent, no code should be coloured in RED.

  3. AFTER you have the proper indentation, read your code to make sure z_wb has been defined before it is called. After that, submit it again and see what happens.

The quickest way to finish this is to slowly and carefully follow through the suggestions, and make sure you understand what each line of code is doing.

Raymond

Hello @26_Komal_Kamble,

Please don’t repeat posting the same question, and not to share your assignment code here. Sharing assignment code violates the honor code.

Please follow through my suggestions for the problems.

Raymond

Thankyou so much but can u please help me a little more? The error of mine is not sloved yet.

Hello @26_Komal_Kamble,

You need to be specific about the problem, then we read it, and try to make suggestions. For example, there is no information about what the problem is in your last reply. There are many things we cannot help you with, and for example, we cannot fix the bugs in your solution for you.

Since I have replied with my suggestions previously, I hope you will tell me how each of them goes, and if you are facing a different error, please share the traceback with us. However, never share your assignment code here.

Raymond

NameError Traceback (most recent call last)
in
** 3 initial_b = 0.**
** 4 **
----> 5 dj_db, dj_dw = compute_gradient(X_train, y_train, initial_w, initial_b)
** 6 print(f’dj_db at initial w (zeros):{dj_db}’ )**
** 7 print(f’dj_dw at initial w (zeros):{dj_dw.tolist()}’ )**

in compute_gradient(X, y, w, b, lambda_)
** 9 for i in range(m):**
** 10 # Calculate f_wb (exactly as you did in the compute_cost function above)**
—> 11 f_wb = sigmoid(z_wb)
** 12 **
** 13 # Calculate the gradient for b from this example**

NameError: name ‘z_wb’ is not defined

The error is this.Can u please help me how to define z_wb? I’m honestly not able to do this please help me out because my course is ending tommorrow.

Hello @26_Komal_Kamble,

You are on UNQ_C2, and after this there are 4 more to go. I understand you want to finish it before tomorrow, but let’s calm down, and do it step by step. It does not take 24 hours to read through every word of this notebook, but if we carefully read through everything, we probably can finish it in an hour.

Do you know there are hints under each exercise cell? For example, this is part of the hint for UNQ_C2:

image

It has actually demonstrated to you how to define z_wb. z_wb = 0 means “we assign zero to a variable called z_wb”, so, if z_wb has never been defined before, that line will define it (by assigning a value to it).

I drew 2 arrows to point to two later lines that actually USE z_wb. Look, z_wb is defined BEFORE it is used! Did you follow the code skeleton given in the hint? If not, perhaps you can try it out!

Cheers,
Raymond

I’m on UNQ_C3 not C2.

Of course, but if you check out the hint on UNQ_C3:

It says the way to calculate f_wb is exactly as you did in UNQ_C2!

Shouldn’t we then look at how UNQ_C2 does it?

Raymond

I have tried using hint but still its giving me error

The hint did define z_wb, and the error message said you didn’t define the z_wb. Did you define z_wb?

{code removed by mentor}

You didn’t define z_wb.

The hint asks you to refer back to UNQ_C2 for how to calculate f_wb:

And this is how UNQ_C2 calculate f_wb:

In UNQ_C2, it does NOT calculate f_wb just with one line. It first define z_wb, then loop over range(n) to accumulate values to z_wb, and finally use the resulting z_wb to calculate f_wb.

You said you have passed UNQ_C2, please go back there to check out how z_wb has changed from 0 to some values before it is finally used to compute f_wb.

I think the problem here is that perhaps you thought it took only 1 line to compute f_wb, but missed out all those necessary previous steps.

This is all I can share with you.

I did it but now I’m getting this error
I’m gonna delete my message once u reply me

You don’t need to delete the screenshot for error traceback. We only can’t share assignment code here.

What did you get running the code cell right above? I mean the cell that has this code:

# Compute and display gradient with w initialized to zeroes
initial_w = np.zeros(n)
initial_b = 0.

dj_db, dj_dw = compute_gradient(X_train, y_train, initial_w, initial_b)
print(f'dj_db at initial w (zeros):{dj_db}' )
print(f'dj_dw at initial w (zeros):{dj_dw.tolist()}' )


I got this


this was the output .I didn’t got any error over here