matmul:输入操作数1的核心尺寸0不匹配,带有gufunc签名(n?,k),(k,m?)->(n?,m?)(大小20与10不同)

时间:2020-04-01 10:06:01

标签: python machine-learning scikit-learn

我正在尝试建立线性回归模型。请帮忙

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)

1 个答案:

答案 0 :(得分:0)

我认为在重塑后,您的x_train(我认为是10个维度)的尺寸与x_test(20个维度)不同,因此matmul函数会出错。您应该检查