100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > python 模拟一元线性回归模型

python 模拟一元线性回归模型

时间:2022-12-12 06:09:17

相关推荐

python 模拟一元线性回归模型

python代码:

import numpy as nparrX=np.random.randint(0,100,30)#print(arrX)arrY=arrX*5+3#print(arrY)for i in range(30):rand=2*np.random.random()-1arrY[i]+=randsum=0for i in arrX:sum+=iexp_x=sum/30;#x的平均值sum=0for i in arrY:sum+=iexp_y=sum/30#y的平均值sum=0for i in range(0,len(arrX)):sum+=arrX[i]*arrY[i]exp_xy=sum/30;#xy的平均值sum=0for i in range(0,len(arrX)):sum+=arrX[i]*arrX[i]exp_xx=sum/30;#xx的平均值a=(exp_xy-exp_x*exp_y)/(exp_xx-exp_x*exp_x)b=exp_y-a*exp_xprint(a,b)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。