# C2\_W3\_Lab 2\_Query

**URL:** <https://community.deeplearning.ai/t/c2-w3-lab-2-query/385213>\
**Category:** Calculus for Machine Learning and Data Science\
**Tags:** week-module-3\
**Created:** [July 14, 2023, 2:01pm UTC](https://community.deeplearning.ai/t/c2-w3-lab-2-query/385213 "2023-07-14T14:01:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Debatreyo\_Roy](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/debatreyo_roy/32/50401_2.png) [@Debatreyo\_Roy](https://community.deeplearning.ai/u/Debatreyo_Roy)\
**Post date:** [July 14, 2023, 2:01pm UTC](https://community.deeplearning.ai/t/c2-w3-lab-2-query/385213/1 "2023-07-14T14:01:24Z")

</div>

```auto
def plot_decision_boundary(X, Y, parameters):
    W = parameters["W"]
    b = parameters["b"]

    fig, ax = plt.subplots()
    plt.scatter(X[0, :], X[1, :], c=Y, cmap=colors.ListedColormap(['blue', 'red']));
    
    x_line = np.arange(np.min(X[0,:]),np.max(X[0,:])*1.1, 0.1)
    ax.plot(x_line, - W[0,0] / W[0,1] * x_line + -b[0,0] / W[0,1] , color="black")
    plt.plot()
    plt.show()
    
plot_decision_boundary(X, Y, parameters)

```

Kindly **explain** this part:

```auto
plt.scatter(X[0, :], X[1, :], c=Y, cmap=colors.ListedColormap(['blue', 'red']));
    
    x_line = np.arange(np.min(X[0,:]),np.max(X[0,:])*1.1, 0.1)
    ax.plot(x_line, - W[0,0] / W[0,1] * x_line + -b[0,0] / W[0,1] , color="black")

```

1. What does the **arguments in ax.plot** mean? _Equation of a line_ it seems.

---

<div class="post-metadata">

**Author:** ![Elemento](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/elemento/32/854_2.png) [@Elemento](https://community.deeplearning.ai/u/Elemento)\
**Post date:** [July 18, 2023, 1:44pm UTC](https://community.deeplearning.ai/t/c2-w3-lab-2-query/385213/2 "2023-07-18T13:44:38Z")

</div>

Hey @Debatreyo_Roy,

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

```auto
 plt.scatter(X[0, :], X[1, :], c=Y, cmap=colors.ListedColormap(['blue', 'red']));

```

In section 2.2 - Dataset, we can see that `X` is a 2-dimensional dataset, i.e., it has 30 samples, each sample containing 2 features. So, to plot `X` in 2-dimensions, we have used `plt.scatter()`, which requires the `x` and `y` co-ordinates for all the 30 samples in our dataset. So, `X[0, :]` represents the x-coordinates of the 30 samples, and `X[1, :]` represents the y-coordinates of the 30 samples in our dataset. However, as you can see in the above plot, there are only 4 points visible. This is because the dataset doesn’t have 30 unique samples, instead the dataset has 4 unique samples only.

* * *

```auto
x_line = np.arange(np.min(X[0,:]),np.max(X[0,:])*1.1, 0.1)
ax.plot(x_line, - W[0,0] / W[0,1] * x_line + -b[0,0] / W[0,1] , color="black")

```

Now, let’s consider the above lines of code. These plot a straight line in the 2-dimensional space, using the learnt parameters. In the lab, we have considered the following equation of line: W\_1 x\_1 + W\_2 x\_2 + b = 0, so, if we try to find out x\_2 (_which is plotted on the Y dimension_), in terms of x\_1 (_which is plotted on the X dimension_), we will get:

x\_2 = \frac{-W\_1}{W\_2} x\_1 + \frac{-b}{W\_2}

Now, we are trying to plot the decision boundary based on the learnt parameters. So, we sample a number of points on the x-axis, specifically between the min and max value of the x-coordinates of our samples, represented by `x_line`. For these sampled x-coordinates, we compute the y-coordinates using the above equation, and we plot the line, i.e., the decision boundary.

Voila, we are done 🥳 Let us know if this helps.

Cheers,  
Elemento
