最最最简单的线性回归的例子
2018-06-06 本文已影响0人
广州老李
假设y=aX+b
录入X的数据,y的数据,然后作图。
from sklearn import linear_model
import matplotlib.pyplot as plt
model = linear_model.LinearRegression()
X = [[1.01], [0.49], [0.31], [1.51], [0.37], [0.73], [1.53], [0.56],
[0.41], [0.74], [0.63], [0.6], [2.06], [1.1], [1.31]]
y = [7366, 985, 544, 9140, 493, 3011, 11413, 1814, 876, 2690, 1190, 4172, 11764, 4682, 6172]
plt.scatter(X, y)
model.fit(X, y)
plt.plot(X, model.intercept_ + model.coef_ * X, color='red', inewidth='3')
plt.show()