1. 导入数据
import numpy as np
x = np.array([1., 2., 3., 4., 5.])
y = np.array([1., 3., 2., 3., 5.])
x_new = x.reshape([-1,1])
2. 图形表示数据
import matplotlib.pyplot as plt
plt.scatter(x,y)
plt.show()
3. 简单线性回归
from sklearn.linear_model import LinearRegression
reg = LinearRegression()
reg.fit(x_new,y)
reg.predict(x_new)
4. 图形表示结果
y_predict = reg.predict(x_new)
plt.scatter(x,y)
plt.plot(x,y_predict,color = 'r')
plt.show()
5. 算法评测
reg.score(x_new,y)