可视化结构是这样的,print(z)全是1,将x,y输出发现并没有错误,很疑惑,求教
神经元的代码是这样:
class Perceptron(object): def __init__(self,eta=0.01,n_iter=10): self.eta=eta self.n_iter=n_iter pass def net_input(self,X): return np.dot(X,self.w_[1:])+self.w_[0] pass def predict(self,X): return np.where(self.net_input(X)>=0.0,1,-1) pass def fit(self,x,y): self.w_=np.zeros(1+x.shape[1]) self.errors_=[] for _ in range(self.n_iter): errors=0 for xi ,target in zip (x,y): update=self.eta*(target-self.predict(xi)) self.w_[1:]+=update*xi self.w_[0]+=update errors+=int(update !=0.0) self.errors_.append(errors) pass pass pass
训练的代码是这样:
ppn=Perceptron(eta=0.01,n_iter=10) ppn.fit(x,y)
看看你的输入数据