Back to questions
JuniorTheoryCommon
What does this program print?
import numpy as np
def gini(y):
p = np.mean(y)
return 1 - p ** 2 - (1 - p) ** 2
print(gini(np.array([1, 1, 1, 1])), gini(np.array([0, 1, 1, 0])))0.0 0.5
- Expecting
1.0for the pure group: Gini measures how mixed the classes are, so a group of one class gets0.0, not the maximum. - Expecting
1.0for the half-and-half group: with two classes Gini peaks at1 - 0.25 - 0.25 = 0.5, so it never reaches1.0.
- Which of two candidate splits does a decision tree prefer, the one with the lower or the higher weighted Gini?
- Why are the Gini values of the two child groups weighted by their sizes when a split is scored?