【问题标题】:Multiple Linear Regression ValueError多元线性回归值错误
【发布时间】:2020-10-25 13:54:43
【问题描述】:

我一直试图让我的线性回归模型预测到某个目的地的票价,但是,我不断收到此错误:

ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 3 is different from 1)

我的代码:

df = pd.read_csv("data.csv")
df.dropna(inplace=True)
x = df[["Distances","Flight_time","Total_Staff_Pay"]]
y = df[["Price"]]
x_train, x_test, y_train, y_test = train_test_split(x, y, train_size = 0.5, test_size = 0.5, random_state=1)
regression = LinearRegression()
regression.fit(x_train,y_train)


#predicting airport
a = [[3417.33],[7.30178432893716],[4804.57408844065]]
print(regression.predict(a))

我看过其他问题/答案,它们并没有真正帮助。

【问题讨论】:

  • 试试a = [[3417.33,7.30178432893716,4804.57408844065]]。共享数据,以便重现错误

标签: python pandas machine-learning regression linear-regression


【解决方案1】:

这应该可以工作

a = [[3417.33,7.30178432893716,4804.57408844065]]

一行代表一个观察结果,因此应该传递为1x3而不是3x1

【讨论】:

    猜你喜欢
    • 2021-01-12
    • 1970-01-01
    • 2010-11-23
    • 2017-10-13
    • 2013-07-17
    • 2014-05-20
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    相关资源
    最近更新 更多