-1
嘗試這種代碼:線性迴歸返回不同的結果綜合參數
from sklearn import linear_model
import numpy as np
x1 = np.arange(0,10,0.1)
x2 = x1*10
y = 2*x1 + 3*x2
X = np.vstack((x1, x2)).transpose()
reg_model = linear_model.LinearRegression()
reg_model.fit(X,y)
print reg_model.coef_
# should be [2,3]
print reg_model.predict([5,6])
# should be 2*5 + 3*6 = 28
print reg_model.intercept_
# perfectly at the expected value of 0
print reg_model.score(X,y)
# seems to be rather confident to be right
的結果是
- [0.31683168 3.16831683]
- 20.5940594059
- 0.0
- 1.0
因此不是我所期望的 - 它們與用於合成數據的參數不同。這是爲什麼?