{
    "name": "Gini Impurity Calculator",
    "url": "https://calculators.geekmidst.com/calculators/gini-impurity-calculator",
    "markdown": "https://calculators.geekmidst.com/calculators/gini-impurity-calculator.md",
    "category": "Statistics & probability",
    "description": "Calculate the Gini impurity of a node from its class counts, with the maximum possible impurity, a normalised score and the entropy for comparison.",
    "summary": "Gini impurity is the chance that two items drawn at random (with replacement) from a node belong to different classes. A pure node scores 0.",
    "also_called": [
        "Gini index calculator (decision trees)"
    ],
    "applies_to": "Worldwide",
    "last_updated": "2026-10-29",
    "computation": "Results are computed in the visitor’s browser on the HTML page. This API describes the calculator; it does not compute results.",
    "inputs": [
        {
            "name": "counts",
            "label": "Items in each class",
            "type": "textarea",
            "default": "9, 5"
        }
    ],
    "outputs": [
        {
            "key": "gini",
            "label": "Gini impurity",
            "format": "number"
        },
        {
            "key": "max_gini",
            "label": "Maximum for this many classes",
            "format": "number"
        },
        {
            "key": "normalised",
            "label": "Normalised (0–1)",
            "format": "number"
        },
        {
            "key": "entropy_bits",
            "label": "Entropy (bits), for comparison",
            "format": "number"
        },
        {
            "key": "total",
            "label": "Total items",
            "format": "number"
        }
    ],
    "formula": {
        "text": "G = 1 − Σ p_i²;  G_max = 1 − 1 ÷ k",
        "variables": {
            "p_i": "share of items in class i",
            "k": "number of classes"
        }
    },
    "worked_example": {
        "inputs": {
            "counts": "9, 5"
        },
        "steps": [
            "Shares: 9 ÷ 14 and 5 ÷ 14.",
            "G = 1 − (81 + 25) ÷ 196 = 90 ÷ 196 = 0.459184."
        ],
        "result": "A node with 9 and 5 items has Gini impurity 0.459, close to the two-class maximum of 0.5."
    },
    "interpretation": "Decision trees (CART) choose the split that most reduces weighted Gini impurity. It is not the Gini coefficient of inequality used in economics.",
    "assumptions": [
        "Class shares are estimated from the counts in the node."
    ],
    "limitations": [
        "To score a whole split, use the information gain calculator with the Gini criterion."
    ],
    "rules": null,
    "faqs": [
        {
            "question": "Gini or entropy?",
            "answer": "They rank splits almost identically in practice. Gini is slightly cheaper to compute; entropy penalises very impure nodes a little more."
        },
        {
            "question": "Is this the same as the Gini coefficient?",
            "answer": "No. The Gini coefficient measures inequality of a distribution, such as income; Gini impurity measures class mixing in a node."
        }
    ],
    "sources": [],
    "related": [
        {
            "name": "Information Gain Calculator",
            "url": "https://calculators.geekmidst.com/calculators/information-gain-calculator"
        },
        {
            "name": "Shannon Entropy Calculator",
            "url": "https://calculators.geekmidst.com/calculators/entropy-shannon-calculator"
        },
        {
            "name": "Class Imbalance Ratio Calculator",
            "url": "https://calculators.geekmidst.com/calculators/class-imbalance-ratio-calculator"
        }
    ],
    "disclaimer": null,
    "publisher": "GM¹X CalcVerse"
}