I’m currently struggling with the gradient descent algorithm, I need help:

*{Moderator’s Edit: Solution Code Removed}*

I’m currently struggling with the gradient descent algorithm, I need help:

*{Moderator’s Edit: Solution Code Removed}*

Hi!

z_{w,b}(x^{(i)}) = w ⋅ x^{(i)} + b = w_{0}x_{0}^{(i)} + … + w_{n-1}x_{n-1}^{(i)} + b

the b term should only be added once to z_wb

as the code is right now you are adding b to z_wb, j times

I don’t see anything wrong with the rest of the code.

Hope this helps

1 Like

Hi,

So I done that and still encountered errors:

*{Moderator’s Edit: Solution Code Removed}*

Hey @demmzy15,

Welcome to the community. I guess you have changed the below lines of code from

```
for j in range(n):
z_wb += X[i,j]*w[j]
z_wb += b
```

to

```
for j in range(n):
z_wb = X[i,j]*w[j] + b
```

in your 2 solutions. But in both of these you are essentially doing the same thing, i.e., adding `b`

n times as @SamReiswig pointed out. You are only supposed to add the bias term once as per the formulation z_{w, b}(x^{(i)}) = w . x^{(i)} + b. So, just add the bias term outside the for loop (*once*), and your code should work fine. I hope this helps.

**P.S. - It is strictly against the community guidelines to post the code for any of the assignments publicly. However, you are always welcome to post the traceback for the errors that you are getting on running your code. If a mentor needs to see your code, he/she will ask you to DM your code to him/her.**

Regards,

Elemento