I have been working on this function for hours but haven’t been able to get dw right. I have used different methods (2 for loops and also with the dot function), but I haven’t been able to figure out where I am wrong.

My output is

dj_db at test w and b: -0.5999999999991071
dj_dw at test w and b: [-44.6025974337068, -44.6025974337068]

Hi!
Yes, I did check the hint code below and tried different variations. By the way, I am talking about the function compute_gradient, not compute_gradient_reg. # UNQ_C3 # GRADED FUNCTION: compute_gradient

Your code for C2 is incorrect/incomplete. I am sharing screenshot of the hints which is mentioned just below the grader cell to make your code correct.

Remember the loss_sum is the label in a labeled example. Since this is logistic regression, every value of must either be 0 or 1. In your case you have not initialise loss_sum=0. See the hint images, you will understand.

ERROR IN C3
Also for C3 where you have mentioned f_wb = sigmoid(z_wb) is incorrect as you have initialise z_wb to 0 in the initial line of code

So here for
f_wb apply sigmoid function to the both parameters with the number of examples and while applying sigmoid function remember this hint
As you are doing this, remember that the variables X_train and y_train are not scalar values but matrices of shape ( 𝑚,𝑛 ) and ( 𝑚 ,1) respectively, where 𝑛 is the number of features and 𝑚 is the number of training examples.

This code is incorrect. Use hint section to make this code one line.
for j in range(n):
dj_dw_ij = (f_wb - y[i])* X[i][j]
dj_dw += dj_dw_ij

At the end divide dj_db and dj_dw by total number of examples
dj_dw = dj_dw / m
dj_db = dj_db / m

Hi! Thanks for your response
I don’t understand why f_wb = sigmoid(z_wb) is wrong. In my code, I iterate over all the features using the nested for loop and sum all the values. So, when I do f_wb = sigmoid(z_wb), z_wb is including both features of the training example.
Actually, I am using the hint in Hint to calculate f_wb → More hints to calculate f_wb

Because calculation for z_wb for computation cost differs
z_wb_ij = w[j]*X[i][j]

where as for gradient
z_wb += X[i, j] * w[j]

that’s why notice + sign with = it means z_wb gets adds with this parameters and gets update to the next z_wb where again z_wb += b adds with bias

so you need to apply the sigmoid to the parameters in a different way where in the update parameter X is tuple with i range and w which further gets added here with one more bias. (I explained the whole code for f_wb

Omg, I finally could do it! Haha. The error was also in assigning the partial derivative of J over b. It works now.
Thank you so much for your assistance and patience