Comments (6)
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 !
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.
@xshaun Thanks for your reply. I mean how to draw the decison boundary line . I can only do it like this.
Thanks all the same !
谢谢您的回复!我的意思是如何画出和那一样的边界分类图片。这个决策边界,很像Sigmoid函数。
我就觉得好奇,一直没能实现,谅解我的愚昧!仍然感谢您的指点!
from 100-days-of-ml-code-chinese-version.
@xshaun Thanks for your reply. I mean how to draw the decison boundary line . I can only do it like this.
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.
@xshaun Thanks very much sincerely. I have finished it.
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 .
anyway, thanks again, i feel sorry to waste your time.
from 100-days-of-ml-code-chinese-version.
@xshaun Thanks very much sincerely. I have finished it.
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 .
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.
@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)
- New Repository for Chinese Translation HOT 8
- Deo hay
- Day3 HOT 3
- Data.csv 文件哪里来 HOT 2
- 请问你这种图是用什么软件做的? HOT 1
- 这个项目好久没有更新了 HOT 1
- English translation HOT 1
- 代码中的from sklearn.cross_validation import train_test_split 在scikit-learn中没有 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 100-days-of-ml-code-chinese-version.