我正在尝试建立线性回归模型。请帮帮忙
database = pd.read_csv('Salary_Data.csv')
x = database.iloc[:,0].values
y = database.iloc[:,1].values
x_train = x_train.reshape(1,-1)
y_train = y_train.reshape(1,-1)
x_test = x_test.reshape(1,-1)
y_test = y_test.reshape(1,-1)
from sklearn.linear_model import LinearRegression
regressor= LinearRegression()
regressor.fit(x_train, y_train)
#predicting the test set results
y_pred = regressor.predict(x_test)
错误是:
ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 20 is different from 10)
发布于 2020-12-05 14:02:10
我认为在重塑之后,您的x_train
(我假设是10个维度)与x_test
(20个维度)具有不同的维度,因此matmul
函数得到错误。你应该检查一下
https://stackoverflow.com/questions/60968380
复制