# Problems with Week 3 Practice Lab Logistic Regression. Problem 1:compute\_gradient function

**URL:** <https://community.deeplearning.ai/t/problems-with-week-3-practice-lab-logistic-regression-problem-1-compute-gradient-function/281462>\
**Category:** Supervised ML: Regression and Classification\
**Tags:** week-module-3\
**Created:** [February 26, 2023, 10:40pm UTC](https://community.deeplearning.ai/t/problems-with-week-3-practice-lab-logistic-regression-problem-1-compute-gradient-function/281462 "2023-02-26T22:40:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Gygi](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Brian\_Gygi](https://community.deeplearning.ai/u/Brian_Gygi)\
**Post date:** [February 26, 2023, 10:40pm UTC](https://community.deeplearning.ai/t/problems-with-week-3-practice-lab-logistic-regression-problem-1-compute-gradient-function/281462/1 "2023-02-26T22:40:55Z")

</div>

This is the first of many problems I had with Week 3 Logistic Regression lab  
In cell 13, I defined the compute\_gradient function _exactly_ as suggested in the hints, and yet it gives incorrect results:  
dj\_db at initial w and b (zeros):-0.005050505050504951  
dj\_dw at initial w and b (zeros):[-0.3766963389152976, -0.4509304870421179]  
Expected outputs:  
dj\_db at initial w and b (zeros) -0.1  
dj\_dw at initial w and b (zeros): [-12.00921658929115, -11.262842205513591]  
Then in cell 15, where the compute\_gradient\_test function is called, the results are even worse. There is an assertion error on line 53: Wrong value for dj\_db. Expected: 0.28936094 got: 0.12443210715916564

And the resulting outputs:  
dj\_db at test w and b: -0.010101010101010001  
dj\_dw at test w and b: [-0.7533926778306007, -0.9018609740842394]

Expected outputs:  
dj\_db at test w and b (non-zeros) -0.5999999999991071  
dj\_dw at test w and b (non-zeros): [-44.8313536178737957, -44.37384124953978]

I have attached my Jupiter Notebook  
I will describe the other issues in subsequent posts  
{moderator edit: code removed}

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [February 26, 2023, 11:29pm UTC](https://community.deeplearning.ai/t/problems-with-week-3-practice-lab-logistic-regression-problem-1-compute-gradient-function/281462/2 "2023-02-26T23:29:38Z")

</div>

Please don’t post your code on the forum. That’s not allowed by the community standard.

You made three posts on the forum that all relate to this same issue.

To get correct results for predict() and for the decision boundary graph (your other two posts), you first have to get the correct results for compute\_gradient().

There’s no reason to post about other errors that occur farther down the notebook until you get the first functions correct.

Did you read the “Hint” material for the compute\_gradient() function? I think you will find it useful.

---

<div class="post-metadata">

**Author:** ![Brian\_Gygi](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Brian\_Gygi](https://community.deeplearning.ai/u/Brian_Gygi)\
**Post date:** [February 27, 2023, 5:31pm UTC](https://community.deeplearning.ai/t/problems-with-week-3-practice-lab-logistic-regression-problem-1-compute-gradient-function/281462/3 "2023-02-27T17:31:25Z")

</div>

Hi, did you read my comments? Yes, I implemented the code _EXACTLY_ as directed in the hints. And my code PASSED the tests. So the problem is not in my code, there is something in their implementation that is wrong. Also, as I pointed out, the code in cell 27 that Coursera provides for the gradient descent, which they say just to run, ALSO does not work properly - the solution does not converge and the decision boundary is way wrong. So please let me know what I can do here. If I can’t post my code, how am I supposed to debug the problem? Thanks

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [February 27, 2023, 5:45pm UTC](https://community.deeplearning.ai/t/problems-with-week-3-practice-lab-logistic-regression-problem-1-compute-gradient-function/281462/4 "2023-02-27T17:45:03Z")

</div>

I have replied on your other thread.

---

<div class="post-metadata">

**Author:** ![Haniyeh\_Salehi](https://avatars.discourse-cdn.com/v4/letter/h/ac91a4/32.png) [@Haniyeh\_Salehi](https://community.deeplearning.ai/u/Haniyeh_Salehi)\
**Post date:** [June 2, 2023, 5:23pm UTC](https://community.deeplearning.ai/t/problems-with-week-3-practice-lab-logistic-regression-problem-1-compute-gradient-function/281462/5 "2023-06-02T17:23:12Z")

</div>

How was it resolved? Where is the other thread? I have the same problem!

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [June 2, 2023, 5:24pm UTC](https://community.deeplearning.ai/t/problems-with-week-3-practice-lab-logistic-regression-problem-1-compute-gradient-function/281462/6 "2023-06-02T17:24:05Z")

</div>

@Haniyeh_Salehi, please start a new thread for your issue, and provide the full details (but do not post your code).

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [June 2, 2023, 5:24pm UTC](https://community.deeplearning.ai/t/problems-with-week-3-practice-lab-logistic-regression-problem-1-compute-gradient-function/281462/7 "2023-06-02T17:24:24Z")

</div>

Closed on June 2, 2023, 5:24pm UTC


