#线性分割前面产生的点
yn=np.zeros([N,1])
for i in range(N):
#point is blow line
if(f(xn[i,0])>=xn[i,1]):
yn[i]=1
plt.plot(xn[i,0],xn[i,1],'bo',markersize=12)
#point is above line
else:
yn[i]= -1
plt.plot(xn[i,0],xn[i,1],'go',markersize=12)
yn=np.zeros([N,1])
for i in range(N):
#point is blow line
if(f(xn[i,0])>=xn[i,1]):
yn[i]=1
plt.plot(xn[i,0],xn[i,1],'bo',markersize=12)
#point is above line
else:
yn[i]= -1
plt.plot(xn[i,0],xn[i,1],'go',markersize=12)
2018-10-14
#产生新huabu
fig=plt.figure()
#获取当前画布
figa=plt.gca()
#产生100个点
N=100
xn=np.random.rand(N,2)
x=np.linspace(0,1)
#随机产生一条线
a=np.random.rand()
b=np.random.rand()
f=lambda x : a*x+b
plt.plot(x,f(x),'r')
fig=plt.figure()
#获取当前画布
figa=plt.gca()
#产生100个点
N=100
xn=np.random.rand(N,2)
x=np.linspace(0,1)
#随机产生一条线
a=np.random.rand()
b=np.random.rand()
f=lambda x : a*x+b
plt.plot(x,f(x),'r')
2018-10-14
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
plt.rcParams['figure.figsize']=(8.0,6.0)#生成图的大小
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
plt.rcParams['figure.figsize']=(8.0,6.0)#生成图的大小
2018-10-14