当我用 sklearn 做线性回归时,为什么我只得到一个 coef_?

Why I get just one coef_, when I am doing my linear regression with sklearn?

这是我的代码和下面的输出。我正在用 sklearn-lib 尝试它, 有效。也许 x.reshape 是假的?

import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sympy.stats import E

#My Data
y = np.array([1.88,3.65,5.86,8.43,11.47,15.98])
x = np.array([1,2,3,4,5,6])

linreg = LinearRegression()

#Grafikgrösse einstellen
x = x.reshape(-1,1)
linreg.fit(x,y)

y_pred = linreg.predict(x)

plt.scatter(x,y)
plt.plot(x,y_pred, color="red")
plt.title("'Linearer Verlauf' durch t=0")
plt.xlabel("Anzahl Umdrehungen")
plt.ylabel("Periode(s)")
plt.legend(['t1'])
plt.show()
print("r^2 =",linreg.score(x,y))
print(linreg.coef_)

等式:y = a*x + b

你的 alinreg.coef_ 项计算,它有一个值(因为只有一个项依赖于 x+b 项由 linreg.intercept_,它给出 -1.7746.