Loading...
Compute the Gini impurity of a set of labels.
Gini impurity measures how often a randomly chosen element would be incorrectly classified:
Gini=1−∑k=1Kpk2
where pk is the proportion of class k in the dataset.
A pure node (all same class) has Gini = 0. Maximum impurity for binary classification is 0.5.
Return the Gini impurity rounded to 4 decimal places.
labels = [1, 1, 0, 0, 0]
0.48