# Decision Boundary Plotting

**URL:** <https://community.deeplearning.ai/t/decision-boundary-plotting/406782>\
**Category:** Supervised ML: Regression and Classification\
**Tags:** week-module-3\
**Created:** [August 3, 2023, 12:46pm UTC](https://community.deeplearning.ai/t/decision-boundary-plotting/406782 "2023-08-03T12:46:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abtaal\_Aatif](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Abtaal\_Aatif](https://community.deeplearning.ai/u/Abtaal_Aatif)\
**Post date:** [August 3, 2023, 12:46pm UTC](https://community.deeplearning.ai/t/decision-boundary-plotting/406782/1 "2023-08-03T12:46:58Z")

</div>

To plot the decision boundary don’t we just need the parameter’s equation z = 0 to plot it?

Some sources mention we need to run the model over a range of values and use their output somehow…

Also, how do we go about plotting decision boundaries for polynomial equations?

---

<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:** [August 3, 2023, 5:23pm UTC](https://community.deeplearning.ai/t/decision-boundary-plotting/406782/2 "2023-08-03T17:23:16Z")

</div>

The decision boundary is a function of the weights. If there are two features, then it’s a 2D plot, and you can show the boundary as a contour.

To get the contour where the probability is 0.5, you need to have a grid of weight values for which you compute the predicted value.

---

<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:** [August 3, 2023, 5:24pm UTC](https://community.deeplearning.ai/t/decision-boundary-plotting/406782/3 "2023-08-03T17:24:50Z")

</div>

> [@Abtaal\_Aatif](#):
>
> how do we go about plotting decision boundaries for polynomial equations?

To get a 2D plot, typically you’d use the two lowest-order features as the horizontal and vertical axes, but compute the predicted values using all of the features.

---

<div class="post-metadata">

**Author:** ![Abtaal\_Aatif](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Abtaal\_Aatif](https://community.deeplearning.ai/u/Abtaal_Aatif)\
**Post date:** [August 4, 2023, 3:42am UTC](https://community.deeplearning.ai/t/decision-boundary-plotting/406782/4 "2023-08-04T03:42:00Z")

</div>

Suppose if the function is f(x) = w1(x1^2) + w2(x2^2) + b. How would you go about plotting this? Assume we have already figured out w1 and w2.

[What I am trying to figure out is the step by step procedure from beyond this point and the entire intuitive logic behind each step, so I can achieve it without relying on functions like contourf (still dk how that works)].

---

<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:** [August 4, 2023, 4:11am UTC](https://community.deeplearning.ai/t/decision-boundary-plotting/406782/5 "2023-08-04T04:11:12Z")

</div>

Hello @Abtaal_Aatif,

The question is then how you get the (x\_1, x\_2) pairs that lead to f(x\_1, x\_2) = 0, right? One way to get one such pair is substitute x\_1 = 0 and solve for x\_2 where f(0, x\_2) = 0. Can you develop the whole procedure from this on?

---

<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:** [August 4, 2023, 4:20am UTC](https://community.deeplearning.ai/t/decision-boundary-plotting/406782/6 "2023-08-04T04:20:06Z")

</div>

That would be a 3D plot, since given w1 and w2, you would plot x1 and x2 on the horizontal axes, and f(x) on the vertical axis.

---

<div class="post-metadata">

**Author:** ![Abtaal\_Aatif](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Abtaal\_Aatif](https://community.deeplearning.ai/u/Abtaal_Aatif)\
**Post date:** [August 4, 2023, 5:40am UTC](https://community.deeplearning.ai/t/decision-boundary-plotting/406782/7 "2023-08-04T05:40:21Z")

</div>

So, I fix a value for one variable and calculate value for the other one, and repeat this over the domains of both variables (nested loop). Afterwards, I just plot the correct values which lead to 0.5. Correct?

---

<div class="post-metadata">

**Author:** ![Abtaal\_Aatif](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Abtaal\_Aatif](https://community.deeplearning.ai/u/Abtaal_Aatif)\
**Post date:** [August 4, 2023, 5:41am UTC](https://community.deeplearning.ai/t/decision-boundary-plotting/406782/8 "2023-08-04T05:41:46Z")

</div>

No, for now, I only intend on plotting the 2-D variant of the graph with x1 and x2 on x-axis and y-axis respectively.

---

<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:** [August 4, 2023, 5:50am UTC](https://community.deeplearning.ai/t/decision-boundary-plotting/406782/9 "2023-08-04T05:50:16Z")

</div>

All the pairs you derived need to satisfy f(x\_1, x\_2) =0, and so all those pairs satisfy sigmoid(f(x\_1, x\_2)) = 0.5, and all those pairs are on the boundary. Plotting those pairs gives you the boundary.

---

<div class="post-metadata">

**Author:** ![Abtaal\_Aatif](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Abtaal\_Aatif](https://community.deeplearning.ai/u/Abtaal_Aatif)\
**Post date:** [August 4, 2023, 6:44am UTC](https://community.deeplearning.ai/t/decision-boundary-plotting/406782/10 "2023-08-04T06:44:35Z")

</div>

Got it. Thank you so much 🙂
