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)```
May 24, 2019 2,777 views

## 1 answer to this question.

Hey! Your array shapes seem inconsistent. Try something like this:

```# input, augmented
x = np.array([[1, 1, 1], [0, 0, 0]])
x = np.column_stack((np.ones(len(x)), x))
# predictions
y = np.array([[0, 1]])
# weights, augmented with bias
w = np.random.uniform(-1, 1, (1, 4))

learning_rate = .0001

loss_old = np.inf
for i in range(30000):
h_of_x = w.dot(x.T)
loss = ((h_of_x - y) ** 2).sum()

if abs(loss_old - loss) < 1e-5:
break

w = w - learning_rate * (h_of_x - y).dot(x)
loss_old = loss```
answered May 24, 2019 by Vaishu

## Error using sklearn and linear regression: shapes (1,16) and (1,1) not aligned: 16 (dim 1) != 1 (dim 0)

Based on documents LinearRegression. An x array ...READ MORE

## ERROR: Could not install packages opencv-contrib-python due to an EnvironmentError: [WinError 5] Access is denied:

Hi@akhtar, I think you are trying to install ...READ MORE

## OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /build/opencv-FWWjHr/opencv-2.4.9.1+dfsg/modules/core/src/persistence.cpp,

Hi@akhtar, I think it should work. But make ...READ MORE

+1 vote

## Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-8nhf9w2t/grpcio/

Hi@akhtar, You may get this error because of ...READ MORE

## how do i change string to a list?

suppose you have a string with a ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE