麻烦大神帮我看一下这段代码的错误在哪里
代码如下:
import numpy as np class Perceptron(object): def __init__(self,eta=0.01,n_iter=2): self.eta=eta self.n_iter=n_iter def fit(self,x,y): self.w_=np.zeros(1+x.shape[1]) self.errors_=[] for t in range(0,self.n_iter): errors=0 for k,target in zip(x,y): update=self.eta * (target-self.predict(k)) self.w_[1:]+=update * k self.w_[0]+=update errors+=np.where(update==0.0,1,-1) if errors > x.shape[0]: return (self.w_) else: self.errors_.append(errors) def net_input(self,x): return np.dot(x,self.w_[1:])+self.w_[0] def predict(self,x): return np.where(self.net_input(x)>0.0,-1,1) P1=Perceptron() x1 = [[0,1,2],[0,0,0]] x2=np.array(x1) print(x2) y1=np.array([1,-1]) print(x2.shape) L1=P1.fit(x2,y1) print(L1) print(x2) 谢谢大神,请求对代码进行指点修改,当前对于输入的数据,得到的返回权值是None,请问原因是什么,怎么修改,万分感谢!