Error in code running

Continuing the discussion from Compute_gradient_test(compute_gradient):

{Moderator Edit: Solution Code Removed}

Compute and display cost and gradient with non-zero w and b

test_w = np.array([ 0.2, -0.5])
test_b = -24
dj_db, dj_dw = compute_gradient(X_train, y_train, test_w, test_b)

print(‘dj_db at test w and b:’, dj_db)
print(‘dj_dw at test w and b:’, dj_dw.tolist())

UNIT TESTS

compute_gradient_test(compute_gradient)

and I am getting this error :
dj_db at test w and b: -0.5999999999991071
dj_dw at test w and b: [-44.831353617873795, -44.37384124953978]

ValueError Traceback (most recent call last)
in
8
9 # UNIT TESTS
—> 10 compute_gradient_test(compute_gradient)

~/work/public_tests.py in compute_gradient_test(target)
49 test_w = np.array([1, 0.5, -0.35])
50 test_b = 1.7
—> 51 dj_db, dj_dw = target(X, y, test_w, test_b)
52
53 assert np.isclose(dj_db, 0.28936094), f"Wrong value for dj_db. Expected: {0.28936094} got: {dj_db}"

in compute_gradient(X_train, y_train, test_w, test_b, *argv)
25 test_b = -24
26 for i in range(m):
—> 27 z = np.dot(X_train[i],test_w) + test_b
28 f_wb_i = sigmoid(z)
29 err_i = f_wb_i - y_train[i]

<array_function internals> in dot(*args, **kwargs)

ValueError: shapes (3,) and (2,) not aligned: 3 (dim 0) != 2 (dim 0)

You don’t need to initialize the test_w = np.array([ 0.2, -0.5]) and
test_b = -24 inside the compute_gradient function. They are the arguments of the function and use it as it is. Don’t assign any value to it.

PS: Sharing your code is not allowed. Next time, only share your error.

My gradient descent value is coming out 0.22 where as expected is 0.30 and resultant plot is also way different from the expected one

You are also missing one more thing. After defining the dj_db = ... inside the loop, you also need to dj_db += None. Replace the None with the correct term. Feel free to check the hint.

but current code without that + factor gives correct value of dj_db. now the problem is in the next section where I am running code for gradient descent.

what this error means:

IndexError Traceback (most recent call last)
in
8
9 # UNIT TESTS
—> 10 compute_gradient_test(compute_gradient)

~/work/public_tests.py in compute_gradient_test(target)
49 test_w = np.array([1, 0.5, -0.35])
50 test_b = 1.7
—> 51 dj_db, dj_dw = target(X, y, test_w, test_b)
52
53 assert np.isclose(dj_db, 0.28936094), f"Wrong value for dj_db. Expected: {0.28936094} got: {dj_db}"

in compute_gradient(X_train, y_train, test_w, test_b, *argv)
27 err_i = f_wb_i - y_train[i]
28 for j in range(n):
—> 29 dj_dw[j] = dj_dw[j] + err_i * X_train[i,j] #scalar
30 dj_db = dj_db + err_i
31 dj_dw = dj_dw/m #(n,)

IndexError: index 2 is out of bounds for axis 0 with size 2

You also need to dj_dw[j]+= None. Replace the None with the correct term.