简体   繁体   中英

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

This is my code and the output below. I am trying it with sklearn-lib, witch works. Is maybe x.reshape false ?

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

我的输出

Equation: y = a*x + b

Your a is calculated by linreg.coef_ term and it has one value (since only one term dependent on x . The +b term is accessed by linreg.intercept_ , which gives -1.7746 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM