簡體   English   中英

sklearn 線性回歸中的 Function 方程/使用系數計算得出的結果與 model.predict(x) 不同

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

我正在嘗試獲取使用 sklearn 創建的線性回歸 model 的方程。 但是,當我嘗試使用 model 中的系數手動計算預測時,我得到了奇怪的結果。 我想我在某個地方犯了一個錯誤,但我自己無法弄清楚......

這是我的代碼:

# 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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM