import numpy as np;
import matplotlib
import matplotlib.pyplot as plt
X = np.mat([[1.24,1.27],[1.36,1.74],[1.38,1.64],[1.38,1.82],[1.38,1.90],[1.40,1.70],[1.48,1.82],[1.54,1.82],
[1.56,2.08],[1.14,1.82],[1.18,1.96],[1.20,1.86],[1.26,2.00],[1.28,2.00],[1.30,1.96]]);
#plt.plot(X[:,0],X[:,1],'o')# use pylab to plot x and y
#pl.xlim(0.0, 2.0)# set axis limits
#pl.ylim(0.0, 2.0)
#plt.show()# show the plot on the screen
def perce(X,y,rho,w_ini):
N,C = X.shape # 训练样本集的大小
max_iter = 10000 # 最大允许的迭代次数
w = w_ini # 初始化的参数向量,比如 w_ini=[0;0];
iter = 0 # 迭代计数器,初置为0
mis_clas=N # 分类错误数,可初置为N
while (mis_clas>0 and iter 0:
plt.plot(X[i,0],X[i,1],'ro')# use pylab to plot x and y
else:
plt.plot(X[i,0],X[i,1],'bo')# use pylab to plot x and y
plt.show()# show the plot on the screen
感知器错误分类率=0.000000 当rho=0.050000
[[ 0.1565 ]
[-0.10955]]