Skip to content

Instantly share code, notes, and snippets.

@iskandr
Created August 7, 2013 20:26
Show Gist options
  • Save iskandr/6178289 to your computer and use it in GitHub Desktop.
Save iskandr/6178289 to your computer and use it in GitHub Desktop.
gini score
import numpy as np
LeftCounts = np.array([150,150])
RightCounts = np.array([200,200])
NLeft = sum(LeftCounts)
NRight = sum(RightCounts)
NTotal = float(NLeft + NRight)
LL = np.dot(LeftCounts,LeftCounts)
RR = np.dot(RightCounts,RightCounts)
LeftScore = 1.0 - LL/NLeft**2
RightScore = 1.0 - RR/NRight**2
Score = (NLeft/NTotal) * LeftScore + (NRight / NTotal) * RightScore
print NLeft, NRight, Score
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment