-
Notifications
You must be signed in to change notification settings - Fork 453
/
gini.m
29 lines (25 loc) · 834 Bytes
/
gini.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function score = gini(actual, predicted)
% score = gini(category,posterior)
%
% Calculates the gini score
%
% actual: n*1 matrix of actual values
% predicted: n*1 matrix of predicted values
% score: gini score
%
% Author: Ben Hamner (ben@benhamner.com)
[~,I] = sort(-predicted);
population_delta = 1 / length(actual);
accumulated_population_percentage_sum = 0;
accumulated_loss_percentage_sum = 0;
score = 0;
total_losses = sum(actual);
for i=1:length(actual)
loc = I(i);
accumulated_loss_percentage_sum = accumulated_loss_percentage_sum + ...
actual(loc) / total_losses;
accumulated_population_percentage_sum = accumulated_population_percentage_sum ...
+ population_delta;
score = score + accumulated_loss_percentage_sum - accumulated_population_percentage_sum;
end
score = score / length(actual);