import numpy as np
import matplotlib.pyplot as plt
X=np.array([[1,3,3],
           [1,4,3],
            [1,1,1]])
Y=np.array([1,1,-1])
W=(np.random.random(3)-0.5)*2
print(W)
lr=0.11
n=0
O=0
def update():
    global X,Y,W,lr,n
    n+=1
    O=np.sign(np.dot(X,W.T))
    W_C=lr*((Y-O.T).dot(X))/int(X.shape[0])
    W=W+W_C
for _ in range(100):
    update()
    print(W)
    print(n)
    O=np.sign(np.dot(X,W.T))
    if(O==Y.T).all():
        print("完成")
        break
x1=[3,4]
y1=[3,3]
x2=[1]
y2=[1]
k=- W[1]/W[2]
d=-W[0]/W[2]


xdata=np.linspace(0,10)

plt.figure()
plt.plot(xdata,xdata*k+d,'r')
plt.plot(x1,y1,'bo')
plt.plot(x2,y2,'yo')
plt.show()

最简单的神经网络-感知器-python实现

 

相关文章:

  • 2022-02-09
  • 2022-12-23
  • 2022-02-07
  • 2021-07-08
  • 2021-08-20
  • 2022-02-11
  • 2021-12-09
  • 2022-12-23
猜你喜欢
  • 2022-02-07
  • 2022-02-09
  • 2021-05-15
  • 2022-12-23
  • 2022-01-02
  • 2021-11-30
相关资源
相似解决方案