I am trying to using the .score() method on a fitted Linear Regressor but I am getting an error.
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn import metrics
from sklearn.metrics import mean_squared_error
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3,
random_state = 104)
reg = LinearRegression()
reg.fit(X_train, y_train)
y_pred = reg.predict(X_test)
print("R^2: {}".format(reg.score(X_test, y_test)))
rmse = np.sqrt(mean_squared_error(y_test, y_pred))
print("Root Mean Squared Error: {}".format(rmse))
reg.score(y_test.reshape(-1,1), y_pred.reshape(-1,1))
ValueError: shapes (10719,1) and (16,1) not aligned: 1 (dim 1) != 16 (dim 0)
I should mention that I have already tried to reshape y_pred and y_test so that they match but it still does not work. I am not sure why the error says (16,1); what are these the dimensions for? I have tried searching for similar questions such as this one: Error using sklearn and linear regression: shapes (1,16) and (1,1) not aligned: 16 (dim 1) != 1 (dim 0) but I am still confused.
Edit: Here is the output for the shapes:
print(X_test.shape, y_test.shape, y_pred.shape)
(10719, 16) (10719, 1) (10719, 1)