Posted By

adkatrit on 02/11/11


Tagged

Gini Impurity


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

adkatrit


Gini Impurity


 / Published in: Python
 

  1. def giniimpurity(l):
  2. total=len(l)
  3. count={}
  4. for item in l:
  5. counts.setdefault(item,0)
  6. counts[item+=1]
  7.  
  8. imp=0
  9. for j in l:
  10. f1=float(counts[j])/total
  11. for k in l:
  12. if j==k: continue
  13. f2=float(counts[k])/total
  14. imp+=f1*f2
  15. return imp

Report this snippet  

You need to login to post a comment.