Skip to content

Instantly share code, notes, and snippets.

@esagara

esagara/gini.py Secret

Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save esagara/cfd94c5ffbd58d157291 to your computer and use it in GitHub Desktop.
Save esagara/cfd94c5ffbd58d157291 to your computer and use it in GitHub Desktop.
pop = [1.0,2.0,3.0]
#total = reduce(lambda x,y: x + y, pop) - no lambdas for me
total = sum(pop)
# cummulative = reduce(lambda x,(i,y): x + y * (len(pop) - i - 1),enumerate(pop)) - doesn't work cuz python
cummulative = 0
for i,x in enumerate(pop):
cummulative += x * (len(pop) - i - 1)
area = (cummulative/total + 0.5) / len(pop)
gini = (2 * (0.5 - area))
print gini
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment