# Week 3 code

**URL:** <https://community.deeplearning.ai/t/week-3-code/606036>\
**Category:** Supervised ML: Regression and Classification\
**Tags:** week-module-3\
**Created:** [April 7, 2024, 2:24pm UTC](https://community.deeplearning.ai/t/week-3-code/606036 "2024-04-07T14:24:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jasmine7](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jasmine7](https://community.deeplearning.ai/u/Jasmine7)\
**Post date:** [April 7, 2024, 2:24pm UTC](https://community.deeplearning.ai/t/week-3-code/606036/1 "2024-04-07T14:24:01Z")

</div>

Hello Team need some help please  
What do the following functions mean ? -  
plt.close(‘all’)  
addpt = plt\_one\_addpt\_onclick( x\_train,y\_train, w\_in, b\_in, logistic=False)

 ![image](https://global.discourse-cdn.com/dlai/original/3X/7/1/71074ffdd1e8bb8e2dfd081b492b013d41a42b16.png)

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

---

<div class="post-metadata">

**Author:** ![hackyon](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/hackyon/32/64679_2.png) [@hackyon](https://community.deeplearning.ai/u/hackyon)\
**Post date:** [April 7, 2024, 3:29pm UTC](https://community.deeplearning.ai/t/week-3-code/606036/2 "2024-04-07T15:29:47Z")

</div>

> [@Jasmine7](#):
>
> What do the following functions mean ? -  
> plt.close(‘all’)  
> addpt = plt\_one\_addpt\_onclick( x\_train,y\_train, w\_in, b\_in, logistic=False)

The `close('all')` just closes all existing figures. It needed to tell the plotting library that you’re finished setting up the existing figures. See this [documentation](https://matplotlib.org/2.1.2/api/_as_gen/matplotlib.pyplot.close.html) for more info.

The `plt_one_addpt_onclick()` is a custom function written by coursera staff. It generates the plot you see below, and allows you to add points to the graph by clicking. You can see the code for this function in one of the other files in the assignment. Choose `File` → `Open` from the menu bar and select one of the util files. The implementation should be in one of those.

---

<div class="post-metadata">

**Author:** ![Jasmine7](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jasmine7](https://community.deeplearning.ai/u/Jasmine7)\
**Post date:** [April 8, 2024, 4:11am UTC](https://community.deeplearning.ai/t/week-3-code/606036/3 "2024-04-08T04:11:39Z")

</div>

Thank you why cant we use the plt.plot function instead.  
Is there more documentation available on plt\_one\_addpt\_onclick. I cant find it anywhere. Need to understand why are we using this function versus others ?  
Thank you

---

<div class="post-metadata">

**Author:** ![Jasmine7](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jasmine7](https://community.deeplearning.ai/u/Jasmine7)\
**Post date:** [April 8, 2024, 11:17am UTC](https://community.deeplearning.ai/t/week-3-code/606036/4 "2024-04-08T11:17:38Z")

</div>

Additionally wanted to ask

Hi Team

Quick question - What does the x0 = np.arange(0,6) function do here, how its reflected in the graph ? Thanks

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

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

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/178017_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [April 8, 2024, 12:02pm UTC](https://community.deeplearning.ai/t/week-3-code/606036/5 "2024-04-08T12:02:30Z")

</div>

> [@hackyon](#):
>
> coursera staff

DLAI staff 😜

---

<div class="post-metadata">

**Author:** ![hackyon](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/hackyon/32/64679_2.png) [@hackyon](https://community.deeplearning.ai/u/hackyon)\
**Post date:** [April 8, 2024, 12:20pm UTC](https://community.deeplearning.ai/t/week-3-code/606036/6 "2024-04-08T12:20:48Z")

</div>

> [@Jasmine7](#):
>
> Is there more documentation available on plt\_one\_addpt\_onclick. I cant find it anywhere. Need to understand why are we using this function versus others ?

The `plt_one_addpt_onclick` is a custom function in one of the assignment util files. Choose `File` → `Open` from the menu bar and select one of the util files. The implementation should be in one of those.

I’m pretty sure `plt_one_addpt_onclick` uses `plt.plot` to plot the actual graph.

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/178017_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [April 8, 2024, 1:43pm UTC](https://community.deeplearning.ai/t/week-3-code/606036/7 "2024-04-08T13:43:20Z")

</div>

Hello @Jasmine7

plt\_one\_addpt\_onclick is class function recalled by the programmer or the coder who designed this assignment. it is not universal documented function.

For example:  
class plt\_one\_addpt\_onclick:  
“”" class to run one interactive plot “”"  
def **init** (self, x, y, w, b, logistic=True):  
self.logistic=logistic  
pos = y == 1  
neg = y == 0

You can find similar plt if you search on google.  
Why we are using this function versus others in because we want to plot a graph of the data available in a linear regression analysis.

The reason this was use over others, I would say is to have an understanding on the data is spread in this linear relation, or any regression analysis.

Regards  
DP

---

<div class="post-metadata">

**Author:** ![Jasmine7](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jasmine7](https://community.deeplearning.ai/u/Jasmine7)\
**Post date:** [April 9, 2024, 11:11am UTC](https://community.deeplearning.ai/t/week-3-code/606036/8 "2024-04-09T11:11:24Z")

</div>

Hello mentors any reply for the x0=np.arange(0,6) above, how is it being used in the graph ?

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/178017_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [April 9, 2024, 12:29pm UTC](https://community.deeplearning.ai/t/week-3-code/606036/9 "2024-04-09T12:29:43Z")

</div>

The above code is not from week 3 assignment, so kindly share screenshot from where you have got the codes.

Regards  
DP

---

<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:** [April 9, 2024, 5:33pm UTC](https://community.deeplearning.ai/t/week-3-code/606036/10 "2024-04-09T17:33:49Z")

</div>

> [@Jasmine7](#):
>
> Need to understand why are we using this function versus others ?

Because the plot is actually an interactive window.  
If you don’t need interaction, you can just use the regular plot functions.

---

<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:** [April 9, 2024, 5:39pm UTC](https://community.deeplearning.ai/t/week-3-code/606036/11 "2024-04-09T17:39:58Z")

</div>

> [@Jasmine7](#):
>
> any reply for the x0=np.arange(0,6) above, how is it being used in the graph ?

For the first part of your question, you can easily answer this yourself by looking at the numpy documentation to see what the arange() function does.

[https://numpy.org/doc/stable/reference/generated/numpy.arange.html](https://numpy.org/doc/stable/reference/generated/numpy.arange.html)

Or, you could do your own experiment:  
 ![image](https://global.discourse-cdn.com/dlai/original/3X/7/0/7086730e0e4ff82dc6731fc71b1d55d2ef98f641.png)

For your second question, the x0 values are the x-coordinates for which the plot is going to be made, using the equation “x1 = 3 - x0”.

![image](https://global.discourse-cdn.com/dlai/original/3X/7/5/752d8089eb5de1bda6b14a34db97556dff72b5fc.png)

---

<div class="post-metadata">

**Author:** ![Jasmine7](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jasmine7](https://community.deeplearning.ai/u/Jasmine7)\
**Post date:** [April 11, 2024, 6:39am UTC](https://community.deeplearning.ai/t/week-3-code/606036/12 "2024-04-11T06:39:50Z")

</div>

Thank you so much TMosh. Very helpful, really appreciate the explanation
