Giter VIP home page Giter VIP logo

Comments (6)

xshaun avatar xshaun commented on May 18, 2024

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

from 100-days-of-ml-code-chinese-version.

sczhai avatar sczhai commented on May 18, 2024

@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函数。
我就觉得好奇,一直没能实现,谅解我的愚昧!仍然感谢您的指点!

from 100-days-of-ml-code-chinese-version.

xshaun avatar xshaun commented on May 18, 2024

@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()
.>>>

from 100-days-of-ml-code-chinese-version.

sczhai avatar sczhai commented on May 18, 2024

@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.

from 100-days-of-ml-code-chinese-version.

xshaun avatar xshaun commented on May 18, 2024

@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.

from 100-days-of-ml-code-chinese-version.

sczhai avatar sczhai commented on May 18, 2024

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

from 100-days-of-ml-code-chinese-version.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.