Python: Weighted coefficient of variation

穿精又带淫゛_ 提交于 2019-12-01 13:12:46

This can be done using the statsmodels.stats.weightstats.DescrStatsW class in the statsmodels package for calculating weighted statistics.

from statsmodels.stats.weightstats import DescrStatsW

arr = np.arange(-5, 5)
weights = np.arange(9, -1, -1)  # Same size as arr

dsw = DescrStatsW(arr, weights)
cv = dsw.std / abs(dsw.mean)  # weighted std / abs of weighted mean

print(cv)
1.6583123951777001

For a related statistic, i.e. the weighted gini, see this answer.


Credit: This answer is motivated by one on calculating the weighted standard deviation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!