来自 sklearn 线性回归的函数方程/使用系数计算给出与 model.predict(x) 不同的结果

Function equation from sklearn linear regression / Calculating with coefficients gives different results than model.predict(x)

我正在尝试获取使用 sklearn 创建的线性回归模型的方程式。但是,当我尝试使用模型中的系数手动计算预测时,我得到了奇怪的结果。我想我哪里弄错了,但我自己想不通...

这是我的代码:

# Many data points in Pandas DataFrame "filtered_data"

predictors = ["Druckwinkel korrigiert [°]", "Druckwinkel sq.", "Drehzahl [1/min]"]
regressant = "Kraft [N]"

x = filtered_data[predictors].to_numpy()
y = filtered_data[regressant].to_numpy()

model = LinearRegression()
model.fit(x, y)

print("Intercept:", model.intercept_)
print("Coefficients:", model.coef_)
print("R²:", model.score(x, y))

这会打印:

Intercept: 150070.5970260448
Coefficients: [-1.28305930e+04  2.73978667e+02  1.48116871e-01]
R²: 0.9578737003844259

如果我这样做

model.predict(np.array([28, 28**2, 2768]).reshape(1, -1))

我明白了

array([6023.2553988])

这似乎是合理的。但是如果我像这样使用系数和截距来计算 Y:

def load(contact_angle, shaft_speed):
     return 150070.59702 - 12830.59299 * (contact_angle ** 2) + 273.97866 * contact_angle + 0.14811 * shaft_speed

load(28, 2768)

我明白了

-9901032.920822442

这完全不是我所期望的...

有人能帮忙吗?

我认为您是在 [28, 28**2, 2768] 上进行预测,并且您的手动计算通过了 [28**2, 28, 2768]

解决这个问题:

def load(contact_angle, shaft_speed):
     return 150070.59702 - 12830.59299 * contact_angle + 273.97866 * (contact_angle ** 2) + 0.14811 * shaft_speed

load(28, 2768)