欢迎光临散文网 会员登陆 & 注册

python 计算标准差

2023-04-28 21:39 作者:滴滴嗒嗒滴滴答  | 我要投稿

numpy.std() 求标准差的时候默认是除以 n 的,即是有偏的,np.std无偏样本标准差方式为加入参数 ddof = 1;
pandas.std() 默认是除以n-1 的,即是无偏的,如果想和numpy.std() 一样有偏,需要加上参数ddof=0 ,即pandas.std(ddof=0) ;DataFrame的describe()中就包含有std();

>>> a

array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

>>> np.std(a, ddof = 1)

3.0276503540974917

>>> np.sqrt(((a - np.mean(a)) ** 2).sum() / (a.size - 1))

3.0276503540974917

>>> np.sqrt(( a.var() * a.size) / (a.size - 1))

3.0276503540974917


python 计算标准差的评论 (共 条)

分享到微博请遵守国家法律