Artificial intelligence *的操作数类型不受支持:';浮动';和';非类型';(FFN)
我正在攻读一门关于GUVI wiz的深入学习课程,该课程由IIT Chennai管理,名为PadhaiOneFourthLabs。我现在在前馈神经网络。这个错误是持续的,无论我尝试了多少,都不会消失。我实现的代码是:Artificial intelligence *的操作数类型不受支持:';浮动';和';非类型';(FFN),artificial-intelligence,Artificial Intelligence,我正在攻读一门关于GUVI wiz的深入学习课程,该课程由IIT Chennai管理,名为PadhaiOneFourthLabs。我现在在前馈神经网络。这个错误是持续的,无论我尝试了多少,都不会消失。我实现的代码是: class SigmoidNeuron(): def __init__(self): self.w = None self.b = None def perceptron(self,e): return (np.dot(e,self.w) + s
class SigmoidNeuron():
def __init__(self):
self.w = None
self.b = None
def perceptron(self,e):
return (np.dot(e,self.w) + self.b)
def sigmoid(self,e):
return 1/(1+np.exp(-e))
def grad_w_mse(self,e,f):
f_cal = self.sigmoid(self.perceptron(e))
return (f_cal - f) * f_cal * (1 - f_cal) * e
def grad_b_mse(self,e,f):
f_cal = self.sigmoid(self.perceptron(e))
return (f_cal - f) * f_cal * (1 - f_cal)
def grad_w_ce(self,e,f):
f_cal = self.sigmoid(self.perceptron(e))
if f == 0:
return f_cal * e
elif f == 1:
return -1 * (1-f_cal) * e
else:
raise ValueError("f can only be 0 or 1")
def grad_b_ce(self,e,f):
if f == 0:
return f_cal
elif f == 1:
return -1 * (1-f_cal)
else:
raise ValueError('f can only be 1 or 0')
def fit(self,E,F,epochs= 1,learning_rate= 1, initialise= True, loss_func= "mse", display_loss = False):
if initialise:
self.w = None
self.b = None
if display_loss:
loss = {}
for i in tqdm_notebook(range(epochs), total= epochs, unit = "epoch"):
dw = 0
db = 0
for e,f in zip (E,F):
if loss_func == "mse":
dw += self.grad_w_mse(e,f)
db += self.grad_b_mse(e,f)
elif loss_func == "ce":
dw += self.grad_w_ce(e,f)
db += self.grad_b_ce(e,f)
m = E.shape[1]
self.w -= learning_rate * dw/m
self.b -= learning_rate * db/m
if display_loss:
F_cal = self.sigmoid(self.perceptron(E))
if loss_func == "mse":
loss[i] = mean_squared_error(F,F_cal)
elif loss_func =="ce":
loss[i] = log_loss(F,F_cal)
if display_loss:
plt.plot(list(loss.values()))
plt.xlabel('Epochs')
if loss_func == "mse":
plt.ylabel('Mean Squared Error')
elif loss_func == "ce":
plt.ylabel('Log Loss')
plt.show()
def predict(self,E):
F_cal = []
for e in E:
f_cal = self.sigmoid(self.perceptron(e))
F_cal.append(f_cal)
return np.array(F_cal)
我得到的错误显示为:
TypeError回溯(最近一次调用)
在()
1 S=乙状结肠神经元()
---->2 S.fit(E_序列,F_序列,历元=1000,学习率=0.5,显示丢失=True)
2帧
在感知器中(self,e)
5.
6 def感知器(自我,e):
---->7返回(np.dot(e,self.w)+self.b)
8.
9 def乙状结肠(自身,e):
以点(*args,**kwargs)表示
TypeError:不支持*:“float”和“NoneType”的操作数类型
我尽可能多地修改代码,但不管怎样,错误依然存在
请帮我解决这个问题,以便我能继续进行下去
谢谢
TypeError Traceback (most recent call last)
<ipython-input-30-bd02664ff1b8> in <module>()
1 S = SigmoidNeuron()
----> 2 S.fit(E_train,F_train,epochs = 1000, learning_rate = 0.5, display_loss = True)
2 frames
<ipython-input-23-891427be7d2d> in perceptron(self, e)
5
6 def perceptron(self,e):
----> 7 return (np.dot(e,self.w) + self.b)
8
9 def sigmoid(self,e):
<__array_function__ internals> in dot(*args, **kwargs)
TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'