The value I am getting is wrong. I am trying to use the dot product but it's not working

Viewed 27
# Create matrix X and y
# X has three columns: 
#   - The first column contain all 1s, which is for the intercept
#   - The second and third columns contain features, i.e., the 1st and 2nd columns of data_norm
# y has one column, i.e., the 3rd column of data_norm

X = np.ones_like(data_norm)
#### START YOUR CODE ####
X[:, 1:3] = data_norm[:,0:1]
y = data_norm[:,2]
#### END YOUR CODE ####


# Compute theta using normal equation method
# Hint: use the inv() function imported from numpy.linalg
#### START YOUR CODE ####
theta_method1 = np.dot(np.dot(np.linalg.inv(np.dot(X.transpose() , X)),  X.transpose()) , y)
#### END YOUR CODE ####


# Use the theta obtained to make predictions and compute the residuals
# Hint: use numpy.dot() and numpy.sum(), and avoid using for loops
#### START YOUR CODE ####
y_hat = X * theta_method1
RSS1 = np.sum(np.square(y_hat - y))

The dot product seems wrong. I m not sure what I am doing wrong. I tried normal multiplication but it was giving me operand operator error.

And when trying to find RSS1 it says : ValueError: operands could not be broadcast together with shapes (105,3) (105,)

0 Answers
Related