Skip to content

Instantly share code, notes, and snippets.

@esagara esagara/gini.py Secret
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.