# Week\_3 Programming Assignment - Function 'predict' is incorrect

**URL:** <https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970>\
**Category:** Supervised ML: Regression and Classification\
**Tags:** week-module-3\
**Created:** [July 5, 2022, 4:57am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970 "2022-07-05T04:57:50Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![cajumago](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/cajumago/32/130813_2.png) [@cajumago](https://community.deeplearning.ai/u/cajumago)\
**Post date:** [July 5, 2022, 4:57am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/1 "2022-07-05T04:57:50Z")

</div>

Hola !

Even though the Output of predict value is as expected (_Function ‘predict’_), I got this point incorrect. That causes me less earn points to pass. Would you mind helping me to figure this point out?

### mlsc1w3-ex1

_Code Cell UNQ\_C4: Function ‘predict’ is incorrect. Check implementation._

Thanks!

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [July 5, 2022, 5:00am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/2 "2022-07-05T05:00:58Z")

</div>

Hi Carlos,

Please share your code for UNQ\_C4 on Direct Message 🙂 I can take a look!

Raymond

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [July 5, 2022, 5:17am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/3 "2022-07-05T05:17:00Z")

</div>

Hello Carlos,

Seems you used both the vectorization approach and the for-loop approach to double calculate `z_wb`. Please see if this is the problem?

Cheers!  
Raymond

---

<div class="post-metadata">

**Author:** ![cajumago](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/cajumago/32/130813_2.png) [@cajumago](https://community.deeplearning.ai/u/cajumago)\
**Post date:** [July 5, 2022, 6:35am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/4 "2022-07-05T06:35:37Z")

</div>

Got it. It’s fixed. Thanks, Raymond!

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [July 5, 2022, 8:06am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/5 "2022-07-05T08:06:54Z")

</div>

You are welcome Carlos!

---

<div class="post-metadata">

**Author:** ![Dalila](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@Dalila](https://community.deeplearning.ai/u/Dalila)\
**Post date:** [July 10, 2022, 2:28pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/6 "2022-07-10T14:28:37Z")

</div>

Hi @rmwkwok,  
I have the same problem as Carlos but I think that I implemented z\_wb correctly.  
I can’t find a solution that solves my problem on other posts.  
Can I send you my notebook on Direct Message please ?  
Dalila

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [July 10, 2022, 2:31pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/7 "2022-07-10T14:31:31Z")

</div>

Hi @Dalila, is your problem about UNQ\_C4? If so please send me the code for UNQ\_C4 first on direct message, I will ask for the notebook if needed.

---

<div class="post-metadata">

**Author:** ![Dalila](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@Dalila](https://community.deeplearning.ai/u/Dalila)\
**Post date:** [July 10, 2022, 2:40pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/8 "2022-07-10T14:40:50Z")

</div>

@rmwkwok ,yes, my problem is about UNQ\_C4.  
I just sent you the code on direct message.  
Thanks for your responsiveness 🙂  
Dalila

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [July 10, 2022, 2:44pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/9 "2022-07-10T14:44:31Z")

</div>

Thank you @Dalila, there is a problem in the line for adding bias, please check if you need “+=” or “=”.

Raymond

---

<div class="post-metadata">

**Author:** ![Dalila](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@Dalila](https://community.deeplearning.ai/u/Dalila)\
**Post date:** [July 10, 2022, 2:52pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/10 "2022-07-10T14:52:42Z")

</div>

You were right, my problem was with the bias. I fixed it.  
Thanks Raymond !  
Dalila

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [July 10, 2022, 2:53pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/11 "2022-07-10T14:53:21Z")

</div>

You are welcome Dalila!

---

<div class="post-metadata">

**Author:** ![EitharOqayli](https://avatars.discourse-cdn.com/v4/letter/e/ce73a5/32.png) [@EitharOqayli](https://community.deeplearning.ai/u/EitharOqayli)\
**Post date:** [July 11, 2022, 8:21am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/12 "2022-07-11T08:21:37Z")

</div>

I have a problem with UNQ\_C4 can you help me ?

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [July 11, 2022, 8:44am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/14 "2022-07-11T08:44:56Z")

</div>

@EitharOqayli, and can you please also just share the error message here?

---

<div class="post-metadata">

**Author:** ![EitharOqayli](https://avatars.discourse-cdn.com/v4/letter/e/ce73a5/32.png) [@EitharOqayli](https://community.deeplearning.ai/u/EitharOqayli)\
**Post date:** [July 11, 2022, 8:47am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/15 "2022-07-11T08:47:11Z")

</div>

File “”, line 19  
m, n = X.shape  
^  
IndentationError: unexpected indent

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [July 11, 2022, 8:53am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/16 "2022-07-11T08:53:14Z")

</div>

I see. I suggest you to use 4 white spaces for one level of identation. For example:

`def predict(X, w, b):` is in the zero-th level of indentation, so you don’t need any white spaces before it.  
Anything inside the `predict` will be **at least** in the first indentation level which will all be indented by at least 4 white spaces.  
You have two for-loops.  
Anything inside the outer for-loop will be in the second indentation level which takes 8 white spaces.  
Anything inside the inner for-loop will be in the third indentation level which takes 12 white spaces.

To set all lines to zero-level, select those lines, press “Shift + Tab” once and it will go 4 white-space backward, you can keep pressing it until all go back to the zero-th level, then select the lines you want to move one indentation level up, and press “Tab”, and repeat this step until all indentations are alright.

---

<div class="post-metadata">

**Author:** ![EitharOqayli](https://avatars.discourse-cdn.com/v4/letter/e/ce73a5/32.png) [@EitharOqayli](https://community.deeplearning.ai/u/EitharOqayli)\
**Post date:** [July 11, 2022, 9:11am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/17 "2022-07-11T09:11:41Z")

</div>

thank you so much that worked perfectly ❤

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [July 11, 2022, 9:54am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/18 "2022-07-11T09:54:40Z")

</div>

You are welcome @EitharOqayli!

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [July 11, 2022, 9:54am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-function-predict-is-incorrect/154970/19 "2022-07-11T09:54:52Z")

</div>


