# coding:utf8
import numpy as np
import matplotlib.pyplot as plt
n = 0 # 迭代次数
lr = 0.10 # 学习速率
# 输入数据
X = np.array([[1, 1, 2, 3],
[1, 1, 4, 5],
[1, 1, 1, 1],
[1, 1, 5, 3],
[1, 1, 0, 1]])
print(X)
# 标签
Y = np.array([1, 1, -1, 1, -1])
# 权重初始化,取值范围-1到1
W = (np.random.random(X.shape[1]) - 0.5) * 2
def get_show():
# 正样本
all_x = X[:, 2]
all_y = X[:, 3]
print (all_x )
print(all_x.shape)
print (all_y )
# 负样本
all_negative_x = [1, 0]
all_negative_y = [1, 1]
print(all_negative_x)
print(Y.shape)
print(all_negative_y)
# 计算分界线斜率与截距
k = -W[2] / W[3]
b = -(W[0] + W[1]) / W[3]
# 生成x刻度
xdata = np.linspace(0, 5)
plt.figure()
plt.plot(xdata, xdata * k + b, 'y')
plt.plot(all_x, all_y, 'bo')# 用蓝色,且点的标记用小圆,'o' circle marker
plt.plot(all_negative_x, all_
感知器模型详解
最新推荐文章于 2024-05-26 09:51:47 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)