Hello Everyone,

I am having issue in the graded assignment for the compute_gradient function.

My code is as follows:

def compute_gradient(X, y, w, b, lambda_=1):

“”"

Computes the gradient for logistic regression

```
Args:
X : (ndarray Shape (m,n)) variable such as house size
y : (array_like Shape (m,1)) actual value
w : (array_like Shape (n,1)) values of parameters of the model
b : (scalar) value of parameter of the model
lambda_: unused placeholder.
Returns
dj_dw: (array_like Shape (n,1)) The gradient of the cost w.r.t. the parameters w.
dj_db: (scalar) The gradient of the cost w.r.t. the parameter b.
"""
m, n = X.shape
dj_dw = np.zeros(w.shape)
dj_db = 0.
### START CODE HERE ###
for i in range(m):
z_wb = 0
for j in range(n):
z_wb_ij = X[i, j] * (w[j])
z_wb += z_wb_ij
z_wb += b
f_wb = sigmoid(z_wb)
dj_db_i = f_wb - y[i]
dj_db += dj_db_i
for j in range(n):
dj_dw_ij = (f_wb - y[i])* X[i][j]
dj_dw[j] = dj_dw_ij
dj_dw = dj_dw / m
dj_db = dj_db_i/m
### END CODE HERE ###
return dj_db, dj_dw
```

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 think my code is good but still having different result thus failing the assignment, could anyone please help?

Thank in advance.

Best Regards,

Bhuvan