import numpy as np
import math
import random
w = np.random.randn(3)
alpha = 0.001#学习率
eps = 1e-4
x = np.array([[2104,3],
[1600,3],
[2400,3],
[1416,2],
[3000,4]])
t = np.array([400,330,369,232,540])
e0 = 1
e1 = 2
e2 = 3
for i in range(1000):
diff = w0+np.dot(w[1],x[i,0])+np.dot(w[2]-t[i])-t[i]
e0 = np.sum(w[0]+x[:,i]*w[i])-t[i]
e1 = e0*x[1,i]
e2 = e0*x[2,i]
e=np.array([e0,e1,e2])
if np.linalg.norm(w-e)<=eps:
w = w-alpha*diff*x[i]
print(w)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in
16 e2 = 3
17 for i in range(1000):
---> 18 diff = w0+np.dot(w[1],x[i,0])+np.dot(w[2]-t[i])-t[i]
19 e0 = np.sum(w[0]+x[:,i]*w[i])-t[i]
20 e1 = e0*x[1,i]
<__array_function__ internals> in dot(*args, **kwargs)
TypeError: dot() missing 1 required positional argument: 'b'