Shannon Entropy and Information Gain Calculator

Calculate entropy from probabilities or class counts, and estimate decision-tree information gain after a split.

Information TheoryData ScienceComputer Science Math

Calculate

Parent class counts or probabilities
Child groups for information gain

Use commas inside a group and semicolons between child groups. Example parent: 9,5 and children: 6,2; 3,3.

Please enter valid values.

What this calculator teaches

Shannon entropy measures uncertainty in a probability distribution. Information gain measures how much a split reduces uncertainty.

These ideas are used in decision trees, compression, machine learning, communications, and data science.

Formula & Symbols

ConceptFormulaMeaning
EntropyH = -Σ pᵢ log₂(pᵢ)Measures uncertainty in bits.
Information gainIG = H(parent) - Σ(w_j H(child_j))Reduction in weighted entropy after a split.
Weightw_j = child size / parent sizeLarger child groups count more.

Step-by-Step Examples

Example 1
Binary class entropy
  • Counts are 9 and 5, total 14.
  • Probabilities are 9/14 and 5/14.
  • Compute -p log₂ p for each class and add.
✓ Entropy ≈ 0.940 bits.
Example 2
Information gain
  • Parent entropy is computed first.
  • Compute each child entropy.
  • Subtract weighted child entropy from parent entropy.
✓ Higher gain means a better split.

Where students use this

🎓
High school and college
Use the tool to check homework and understand each step.
📊
Data and modeling
Connect formulas to tables, graphs, and real values.
🧪
Science and engineering
Use math results inside physics, chemistry, and engineering problems.
💻
Computer science
Apply the same logic to algorithms, systems, and numerical work.

Common Mistakes to Avoid

⚠️
Using natural log by accident

Shannon entropy in bits uses log base 2.

⚠️
Not weighting child entropy

Information gain requires weighted average child entropy.

⚠️
Leaving zero probabilities in formula

Terms with p=0 contribute 0, not undefined.

Frequently Asked Questions

What is entropy in data science?
It is a measure of class impurity or uncertainty.
What does information gain mean?
It is the reduction in entropy after splitting data.
Can entropy be zero?
Yes. Entropy is zero when all examples are in one class.
Why use log base 2?
Log base 2 measures information in bits.

Related Math Calculators

Formula Explorer connections

Interpretation: This relationship quantifies information, representation, storage, error, search or computational performance. Assumption: Use the exact encoding, data distribution, machine representation and algorithm assumptions. Real systems also include implementation and hardware overhead.

Sorting Algorithm Comparison Calculator →Binary Search Steps Calculator →Bit Mask Calculator →Math Formula Explorer →