干得好。
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
a所需列表的列表。
y
只是需要一张清单。
model
有许多其他可用的方法和属性。看见
dir(model)
.