a= [-0.10266667,0.02666667,0.016 ,0.06666667,0.08266667]
b= [5.12,26.81,58.82,100.04,148.08]Excel斜率(a,b)中的结果是0.001062,如何在Python中获得相同的结果?
发布于 2022-04-24 06:12:56
这就是你要的。
import numpy as np
from sklearn.linear_model import LinearRegression
x = np.array([5.12,26.81,58.82,100.04,148.08]).reshape((-1, 1))
y = np.array([-0.10266667,0.02666667,0.016 ,0.06666667,0.08266667])
model = LinearRegression().fit(x, y)
print(model.coef_)
# methods and attributes available
print(dir(model))在excel中,SLOPE参数的顺序是y,x。我在这里使用了这些名称,这样就更明显了。
reshape只是使x成为一个列表列表,这是所需的。y只是需要一个列表。model还有许多其他可用的方法和属性。见dir(model)。
https://stackoverflow.com/questions/71985895
复制相似问题