/ Published in: Python
Expand |
Embed | Plain Text
def giniimpurity(l): total=len(l) count={} for item in l: counts.setdefault(item,0) counts[item+=1] imp=0 for j in l: f1=float(counts[j])/total for k in l: if j==k: continue f2=float(counts[k])/total imp+=f1*f2 return imp
You need to login to post a comment.
