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

 1 import  pandas
 2 from matplotlib  import  pyplot
 3 from  scipy.stats  import  linregress
 4 sale=pandas.read_excel('销售.xlsx',dtype={'date':str})
 5 
 6 
 7 slope,intercept,r,p,std_err=linregress(sale.index,sale.revenue)
 8 
 9 exp=sale.index*slope+intercept       
10 
11 pyplot.scatter(sale.index,sale.revenue)   #绘制散点图
12 
13 pyplot.plot(sale.index,exp,color='red')   #绘制直线图
14 
15 pyplot.title(f"y={slope}*x+{intercept}")   #得出线性回归方差
16 
17 pyplot.xticks(sale.index,sale.date,rotation=45)  #sale.index确定刻度大小,sale.date确定刻度上的数据
18 
19 pyplot.tight_layout()
20 pyplot.show()

 

posted @ 2020-06-14 11:24  马蹄哒哒  阅读(353)  评论(0编辑  收藏  举报