Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Who could share me how to draw the gragh ? Thanks #9

Open
sczhai opened this issue May 14, 2020 · 6 comments
Open

Who could share me how to draw the gragh ? Thanks #9

sczhai opened this issue May 14, 2020 · 6 comments

Comments

@sczhai
Copy link

sczhai commented May 14, 2020

Hi, Everybody.
When i see the ML coursee, I find it's useful. Especial, i have interested in Day4.jpg about Logistic Regression.
But I have a question , How to draw the picture ? Could you share me the code ?
Thanks a lot !
image

@sczhai sczhai changed the title Who could guide me how to draw the gragh ? Thanks Who could share me how to draw the gragh ? Thanks May 14, 2020
@xshaun
Copy link

xshaun commented May 17, 2020

Hi, Everybody.

When i see the ML coursee, I find it's useful. Especial, i have interested in Day4.jpg about Logistic Regression.

But I have a question , How to draw the picture ? Could you share me the code ?

Thanks a lot !

image

Hope this link is useful to you, where there are a few examples on drawing pictures with matploylib. If you wanna the similar pictures like the above, just combine different shapes. It’s not hard.
https://matplotlib.org/examples/index.html

@sczhai
Copy link
Author

sczhai commented May 18, 2020

@xshaun Thanks for your reply. I mean how to draw the decison boundary line . I can only do it like this.
image
Thanks all the same !

谢谢您的回复!我的意思是如何画出和那一样的边界分类图片。这个决策边界,很像Sigmoid函数。
我就觉得好奇,一直没能实现,谅解我的愚昧!仍然感谢您的指点!

@xshaun
Copy link

xshaun commented May 19, 2020

@xshaun Thanks for your reply. I mean how to draw the decison boundary line . I can only do it like this.

image

Thanks all the same !

谢谢您的回复!我的意思是如何画出和那一样的边界分类图片。这个决策边界,很像Sigmoid函数。

我就觉得好奇,一直没能实现,谅解我的愚昧!仍然感谢您的指点!

The following is a simple demo that involves the code for drawing sigmoid function. Hope it can help you.

Python3
.>>> import numpy as np
.>>> import pylab as p
.>>>
.>>> sigmoid = lambda x : 1 / (1 + np.exp(-x))
.>>> x = np.arange(-10., 10., 0.2)
.>>>
.>>> p.plot(x, sigmoid(x), color='red', lw=2)
[<matplotlib.lines.Line2D object at 0x10e176c90>]
.>>> p.show()
.>>>

@sczhai
Copy link
Author

sczhai commented May 20, 2020

@xshaun Thanks very much sincerely. I have finished it.
image
here is my code as follows:
i=1
x=[]
y=[]
while i<=500:
a=random.uniform(0,5)
b=random.uniform(0,1)
x.append(a)
y.append(b)
i=i+1
plt.scatter(x,y)
x=np.linspace(0,5,500)
y=1/(1+np.exp(-1.5*x+4.5))
plt.plot(x,y,"r--")
plt.show()

But how to use the curve to make the classfication clearly.
The below is really what i want to get. maybe the curve is decsion boundary, not sigmoid .
image

anyway, thanks again, i feel sorry to waste your time.

@xshaun
Copy link

xshaun commented May 20, 2020

@xshaun Thanks very much sincerely. I have finished it.

image

here is my code as follows:

i=1

x=[]

y=[]

while i<=500:

a=random.uniform(0,5)

b=random.uniform(0,1)

x.append(a)

y.append(b)

i=i+1

plt.scatter(x,y)

x=np.linspace(0,5,500)

y=1/(1+np.exp(-1.5*x+4.5))

plt.plot(x,y,"r--")

plt.show()

But how to use the curve to make the classfication clearly.

The below is really what i want to get. maybe the curve is decsion boundary, not sigmoid .

image

anyway, thanks again, i feel sorry to waste your time.

Hello,
The green curve is the boundary we want to seek. It’s also the expected output of the logistic regression algorithm.

One approach to draw a figure like that is to define a boundary (y=f(x)) by yourself and random a few points at the both sides of the boundary. Then, you can use logistic regression algorithm to seek a curve as close to the defined boundary as possible. This way can also verify the availability of your code.

After several iterations, you will get a couple of parameters to describe the boundary, like w, b. What you need to do is like:
.>>> x is from -10 to 10 with mini step like 0.1
.>>> y = lambda x : w*fai(x)+b
.>>> plot(x, y,....)

Hope this is useful to you.

@sczhai
Copy link
Author

sczhai commented May 20, 2020

@xshaun Thanks for your patience and guidance again. I will have a try late. Best Regards ,Sincerely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants