Calculator Inputs
Use matching class positions across parent and child nodes.
Formula Used
Each class probability equals its count divided by node size.
How to Use This Calculator
- Enter parent class counts in consistent class order.
- Enter left and right child counts using that order.
- Select one criterion or compare every available criterion.
- Add optional node distributions for wider plot comparisons.
- Choose chart, sorting, precision, and display preferences.
- Press calculate and review gain, tables, and visual patterns.
- Download the chart or calculated node data when needed.
Understanding Node Impurity
Node impurity measures how mixed target classes remain inside a decision tree node. Pure nodes contain one dominant class, while mixed nodes contain several classes. Lower impurity usually indicates clearer separation and more confident final predictions.
Why Impurity Matters
Decision trees evaluate candidate splits by comparing impurity before and after each splitting. A useful split creates child nodes that are purer than their parent. Impurity reduction therefore guides every important branching choice during supervised training.
The Gini Index
Gini impurity estimates the chance of assigning an incorrect random class label. It squares every class probability, then subtracts their sum from one. Values approach zero when one class completely dominates the complete node.
Entropy and Information
Entropy measures predictive uncertainty using logarithms of observed class probabilities. Balanced classes create much higher entropy because outcomes become less predictable. Changing the logarithm base alters numerical scale, but ranking usually remains stable.
Classification Error
Classification error simply subtracts the largest class probability from one. It is simple, intuitive, and generally less sensitive than other measures. Small probability changes may not affect its value until class leadership changes.
Weighted Split Quality
Child impurities must accurately reflect their sample sizes during split evaluation. Larger child nodes receive greater weight within the combined impurity calculation. Information gain equals parent impurity minus the weighted child impurity.
Reading the Plot
Each plotted point represents calculated impurity for one supplied node distribution. Clear labels help compare parents, children, and alternative candidate nodes. Steeper declines often reveal stronger separation across the selected impurity measure.
Choosing a Criterion
Gini often trains quickly and works reliably for practical classification tasks. Entropy emphasizes subtle probability changes and supports information gain interpretation. Classification error remains especially useful for simple reporting and broad comparisons.
Handling Class Imbalance
Imbalanced nodes can appear pure even when minority class performance remains poor. Review class counts carefully alongside impurity before accepting any proposed split. Weighted metrics and external validation provide important additional context for rare classes.
Using the Calculator
Enter parent, left, and right class counts using simple comma separation. Add optional node rows for broader visual comparisons across multiple experiments. Choose criteria, decimal precision, chart style, ordering, and label preferences.
Interpreting Advanced Results
Compare weighted child impurity against the parent value for every available criterion. Positive gain indicates useful improvement, while negative gain signals weaker separation. Large gains are promising, but later independent validation should confirm generalization.
Practical Modeling Guidance
Use impurity plots with reasonable depth limits, pruning, and validation scores. Avoid choosing splits only because one visual difference appears unusually dramatic. Balanced choices yield compact trees, clear rules, stronger predictions.
Frequently Asked Questions
What does node impurity represent?
Node impurity represents class mixture inside one decision tree node. Zero means complete purity under every supported criterion. Larger values indicate greater uncertainty or class diversity.
Which impurity criterion should I choose?
Gini is efficient and commonly used. Entropy gives an information-based interpretation. Classification error is simpler but reacts less strongly to probability changes.
Can I enter probabilities instead of counts?
Yes, positive proportional values produce identical probabilities and impurity. Child weighting still uses entered totals. Use real counts when evaluating an actual split.
Why enforce matching child totals?
A valid binary split should preserve every parent class count. The option detects inconsistent child data. Disable it only for independent node comparisons.
What does positive impurity gain mean?
Positive gain means weighted children are purer than their parent. Larger gains suggest stronger separation. Validation should still confirm the split improves predictive performance.
Why can impurity gain equal zero?
Zero gain appears when splitting does not improve weighted purity. Both children may resemble the parent distribution. Such splits usually add complexity without useful separation.
How does the entropy base affect results?
The logarithm base changes entropy scale. It usually preserves candidate split rankings. Keep one base consistent when comparing experiments or reports.
How many additional nodes can I compare?
You can add up to forty custom node rows. Each row needs matching class positions. Short labels keep crowded charts easier to read.
Does lower impurity always create a better model?
Lower impurity helps local separation, but it cannot guarantee generalization. Deep trees may overfit training data. Validation, pruning, and domain checks support stronger final decisions.