calculating Gini coefficient in Python/numpy

后端 未结 4 938
谎友^
谎友^ 2020-12-09 19:51

i\'m calculating Gini coefficient (similar to: Python - Gini coefficient calculation using Numpy) but i get an odd result. for a uniform distribution sampled from np.r

4条回答
  •  伪装坚强ぢ
    2020-12-09 19:58

    A quick note on the original methodology:

    When calculating Gini coefficients directly from areas under curves with np.traps or another integration method, the first value of the Lorenz curve needs to be 0 so that the area between the origin and the second value is accounted for. The following changes to G(v) fix this:

    yvals = [0]
    for b in bins[1:]:
    

    I also discussed this issue in this answer, where including the origin in those calculations provides an equivalent answer to using the other methods discussed here (which do not need 0 to be appended).

    In short, when calculating Gini coefficients directly using integration, start from the origin. If using the other methods discussed here, then it's not needed.

提交回复
热议问题