代码:
注意:由于笔者的系统内没有题目所要求的字体,所以简化为用英文替代
import numpy as np
x = np.array([[6],[7],[8],[9],[10]])
y =np.array([[10567],[9566],[15678],[13644],[15789]])
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
x_train,y_train,x_test,y_test = train_test_split(x,y,test_size= 0.3)
model=LinearRegression()
model.fit(x,y)
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None,
normalize=False)
y2 = model.predict(x)
#plt.rcParams['font.sans-setattr']='SimHei'
plt.title('link')
plt.xlabel('age/year')
plt.ylabel('redict/dollar')
plt.scatter(x,y,s=60,c='k',marker='o')
plt.plot(x,y2,'r-')
plt.show()
#plt.legend(['真实值','预测值'])
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/0aa02b0eb8294941b5982daa6a4bf0c6.png#pic_center)