Fluorite | Level 6

## Gini Calculation

Hi all,

Any ideas on how the gini measure of diversity  is calculated when creating bins through the interactive binning node? cause i see it alters when i either merge or spliit bins

1 ACCEPTED SOLUTION

Accepted Solutions
SAS Employee

## Re: Gini Calculation

Hi, thanks to one of my R&D colleagues, he wrote up a quick solution using IML, which should match your results in EM.

proc iml;

event={517,365,349,269};

nonevent={233,281,451,535};

sum1=0;

do i=2 to 4;

sum2=0;

im1=i-1;

do j=1 to im1;

sum2=sum2+nonevent;

end;

sum1=sum1 + event*sum2;

end;

sum3=0;

do i=1 to 4;

sum3 = sum3 + event*nonevent;

end;

gini = 100*(1 - (2*sum1 + sum3)/ (1500*1500)) ;

print sum1 sum2 sum3 gini;

quit;

 524016 965 524340 30.1168
4 REPLIES 4
SAS Employee

## Re: Gini Calculation

Hi as you may already know, the Gini statistic tests for differences in bin values with respect to the target (events vs non-events).  As Gini changes in the Interactive Binning node, you get an idea of the validity of your bin cutoffs.

You can find this equation in the EM reference guide in the Interactive Binning node section.

Thanks,

Jonathan

Fluorite | Level 6

## Re: Gini Calculation

Ok i think i am almost there, but how would the formula look like in the following example?

 Value Group Cutoff Event count Non event count Total Event rate MISSING 1 0 0 0 0 AGE <25 2 25.5 517 233 750 68.9% 25.5

SAS Employee

## Re: Gini Calculation

Hi, thanks to one of my R&D colleagues, he wrote up a quick solution using IML, which should match your results in EM.

proc iml;

event={517,365,349,269};

nonevent={233,281,451,535};

sum1=0;

do i=2 to 4;

sum2=0;

im1=i-1;

do j=1 to im1;

sum2=sum2+nonevent;

end;

sum1=sum1 + event*sum2;

end;

sum3=0;

do i=1 to 4;

sum3 = sum3 + event*nonevent;

end;

gini = 100*(1 - (2*sum1 + sum3)/ (1500*1500)) ;

print sum1 sum2 sum3 gini;

quit;

 524016 965 524340 30.1168
Fluorite | Level 6

## Re: Gini Calculation

Thank you very much for your help

Discussion stats
• 4 replies
• 11089 views
• 0 likes
• 2 in conversation