数据预测,制做线性回归方程

import  pandas
from matplotlib  import  pyplot
from  scipy.stats  import  linregress
sale=pandas.read_excel(‘销售.xlsx‘,dtype={‘date‘:str})


slope,intercept,r,p,std_err=linregress(sale.index,sale.revenue)

exp=sale.index*slope+intercept       

pyplot.scatter(sale.index,sale.revenue)   #绘制散点图

pyplot.plot(sale.index,exp,color=‘red‘)   #绘制直线图

pyplot.title(f"y={slope}*x+{intercept}")   #得出线性回归方差

pyplot.xticks(sale.index,sale.date,rotation=45)  #sale.index确定刻度大小,sale.date确定刻度上的数据

pyplot.tight_layout()
pyplot.show()