# Plot decision lines for first layer

**URL:** <https://community.deeplearning.ai/t/plot-decision-lines-for-first-layer/256109>\
**Category:** Advanced Learning Algorithms\
**Tags:** week-module-2\
**Created:** [January 12, 2023, 3:26pm UTC](https://community.deeplearning.ai/t/plot-decision-lines-for-first-layer/256109 "2023-01-12T15:26:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evgy](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@Evgy](https://community.deeplearning.ai/u/Evgy)\
**Post date:** [January 12, 2023, 3:26pm UTC](https://community.deeplearning.ai/t/plot-decision-lines-for-first-layer/256109/1 "2023-01-12T15:26:40Z")

</div>

Hi guys,

In the multi-class lab (week 2), there is stage where the decision boundary lines for the first layer output are added to the plot:

 ![image](https://global.discourse-cdn.com/dlai/original/3X/f/c/fc6e9e0ea57fd4210f7509a86332bcecb870694d.png)

I tried to do the same by myself, and I don’t know if I did it right ☹  
My code is:

line1 = W1[0, 0]/W1[0, 1] \* X\_train[:, 0] + b1[0]  
line2 = W1[1, 0]/W1[1, 1] \* X\_train[:, 0] + b1[1]

plt.scatter(X\_train[:, 0], X\_train[:, 1])  
plt.plot(line1, X\_train[:, 0])  
plt.plot(line2, X\_train[:, 0])  
plt.xlim(-7.7, 7.7)  
plt.ylim(-4.5, 4)  
plt.show()

and the result I get is:  
 ![image](https://global.discourse-cdn.com/dlai/original/3X/1/3/138855c73720bd61174711aba0edb3d3d1234ea9.png)

What do you think? Is this correct or did I miss something?

---

<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:** [January 12, 2023, 11:31pm UTC](https://community.deeplearning.ai/t/plot-decision-lines-for-first-layer/256109/2 "2023-01-12T23:31:36Z")

</div>

Hello @Evgy,

It becomes clearer if we write down the first equation and derive from it step-by-step:

 ![image](https://global.discourse-cdn.com/dlai/original/3X/b/b/bb9c4fb92747eab9d67745a418712117131684fc.png)

Cheers,  
Raymond

---

<div class="post-metadata">

**Author:** ![Evgy](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@Evgy](https://community.deeplearning.ai/u/Evgy)\
**Post date:** [January 15, 2023, 6:52am UTC](https://community.deeplearning.ai/t/plot-decision-lines-for-first-layer/256109/3 "2023-01-15T06:52:11Z")

</div>

Thank you Raymond,  
Now it looks good 🙂

![image](https://global.discourse-cdn.com/dlai/original/3X/4/4/442599b051d5ff613016c36f5cb32fb268f67078.png)

line1 = -W1[0, 0]/W1[0, 1] \* X\_train[:, 0] - b1[0]/W1[0, 1]  
line2 = -W1[1, 0]/W1[1, 1] \* X\_train[:, 0] - b1[1]/W1[1, 1]

plt.scatter(X\_train[:, 0], X\_train[:, 1])  
plt.plot(X\_train[:, 0], line1)  
plt.plot(X\_train[:, 0], line2)  
plt.xlim(-7.7, 7.7)  
plt.ylim(-4.5, 4)  
plt.show()

---

<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:** [January 15, 2023, 7:39am UTC](https://community.deeplearning.ai/t/plot-decision-lines-for-first-layer/256109/4 "2023-01-15T07:39:40Z")

</div>

That’s good, @Evgy!

Raymond
