I have these gradient descent algorithm for multivariate regression but it raises an
ValueError: operands could not be broadcast together with shapes (3,) (3,140).
I checked out other answers on broadcasting errors on stackoverflow and the documentation which says the dimensions of the matrices must be same or either of the matrix must be 1.But how can i make my theta of the same dimension.
Please don't mark it duplicate.
My x has dim (140,3) , y has (140,1), alpha=0.0001
def find_mse(x,y,theta):
return np.sum(np.square(np.matmul(x,theta)-y))*1/len(x)
def gradientDescent(x,y,theta,alpha,iteration):
theta=np.zeros(x.shape[1])
m=len(x)
gradient_df=pd.DataFrame(columns=['coeffs','mse'])
for i in range(iteration):
gradient = (1/m) * np.matmul(x.T, np.matmul(x, theta) - y)
theta = np.mat(theta) - alpha * gradient
cost = compute_cost(X, y, theta)
gradient_df.loc[i] = [theta,cost]
return gradient_df