ML - linear regression

 
import numpy as np
from sklearn import linear_model
import matplotlib.pyplot as plt


x = np.arange(0,3)[:,np.newaxis]  #x = np.array([[0],[1],[2]]) 
y = [2, 3, 4]
x0 = np.array([13,15,17])[:,np.newaxis]
y0 = np.array([15,17,19])
reg = linear_model.LinearRegression()
reg.fit (x, y)
y1 = reg.predict(x0)
print(reg.coef_)        
print(reg.intercept_)
plt.scatter(x0,y0,color='k')
plt.plot(x0,y1,color='b')
plt.xlabel('X')
plt.ylabel('y')
plt.show()

 

 

 

posted @ 2018-01-19 17:16  YWU  阅读(114)  评论(0)    收藏  举报