Gini Impurity
noun
say it: “JEE-nee im-PYOOR-ih-tee” /ˈdʒini ɪmˈpjʊrəti/
A measure of how mixed the categories in a group are, from 0 when all are the same to higher values for a more even mix.
What is Gini impurity?
Gini impurity is how mixed a group's classes are: 0 when every example is the same class, 0.5 for an even mix of two. A decision tree picks each question by how much it lowers the impurity of the groups it makes. It's 1 minus the sum of each class's share squared.
def gini(shares):
return 1 - sum(p ** 2 for p in shares)
print(gini([1.0])) # 0.0: all apples
print(gini([0.5, 0.5])) # 0.5: half and half
print(round(gini([0.8, 0.2]), 2)) # 0.32
In a sentence
- “The tree chose the question that lowered the Gini impurity the most.”
- “The split left a group of only apples, with a Gini impurity of 0.”
Level: Freelancer · More AI Basics terms at this level
Updated