Here is my attempt to perform linear regression utilizing just numpy and linear algebra :
def linear_function(w , x , b):
return np.dot(w , x) + b
x = np.array([[1, 1,1],[0, 0,0]])
y = np.array([0,1])
w = np.random.uniform(-1,1,(1 , 3))
print(w)
learning_rate = .0001
xT = x.T
yT = y.T
for i in range(30000):
h_of_x = linear_function(w , xT , 1)
loss = h_of_x - yT
if i % 10000 == 0:
print(loss , w)
w = w + np.multiply(-learning_rate , loss)
linear_function(w , x , 1)
This causes an error :
ValueError Traceback (most recent call last)
<ipython-input-137-130a39956c7f> in <module>()
24 if i % 10000 == 0:
25 print(loss , w)
---> 26 w = w + np.multiply(-learning_rate , loss)
27
28 linear_function(w , x , 1)
ValueError: operands could not be broadcast together with shapes (1,3) (1,2)