induwara.lk
induwara.lkMachine Learning · Decision Trees

Information Gain Calculator

Compute the information gain and gain ratio of a decision-tree split from the class counts of each branch. Every step is shown — parent entropy, each child's entropy, the weighted child entropy, split information — so you can check your homework. The exact metric ID3 and C4.5 use. Runs in your browser, no signup.

By Induwara AshinsanaUpdated Jul 12, 2026
Information gainof a split
ID3 & C4.5 (Quinlan)
GroupYesNo
Examples
Information gain
0.2467 bits
Higher = better split
Gain ratio
0.1564
C4.5 split criterion
Parent entropy
0.9403 bits
N = 14
Weighted child entropy
0.6935 bits
Σ wⱼ·H(childⱼ)

Gain = H(parent) − Σ wⱼ·H(childⱼ) = 0.9403 0.6935 = 0.2467 bits

Cross-checked as mutual information I(class ; split) = 0.2467.

Split info = −Σ wⱼ·log wⱼ = 1.5774 · Gain ratio = Gain / Split info = 0.1564

Parent entropy → after splitgain = 0.2467 bits

Per-group working

GroupYesNoNⱼwⱼH(child)wⱼ·H
Sunny2350.35710.97100.3468
Overcast4040.28570.00000.0000
Rain3250.35710.97100.3468
Parent (root)951410.9403
Weighted child entropy Σ wⱼ·H(childⱼ)0.6935
Gain = H(parent) − Σ wⱼ·H(childⱼ) (Quinlan 1986, ID3) and gain ratio = gain / split info (Quinlan 1993, C4.5), with entropy after Shannon 1948. Log base is a display convention; the gain ratio is the same in bits or nats. Full sources are listed below the calculator.

How it works

Information gain answers one question a decision tree asks at every node: which attribute should I split on? It measures how much a candidate split lowers the uncertainty about the class label, measured in entropy. The metric is the core of Quinlan's ID3 algorithm (1986) and, with the gain-ratio correction, of its successor C4.5 (1993).

Let the parent node hold class counts c₁, …, c_K with total N. Every step builds on Shannon's entropy (1948), using log base 2 so the unit is bits, with the convention 0·log 0 = 0 so pure groups never produce NaN:

  1. Parent entropy. H(parent) = −Σ (cᵢ/N)·log₂(cᵢ/N). This is the uncertainty before the split. It is 0 when the node is pure and maximal (log₂K) when all classes are equally frequent.
  2. Child entropies. Each group j the split produces has its own counts and total Nⱼ. Compute H(childⱼ) with the same entropy formula, and its weight wⱼ = Nⱼ / N.
  3. Weighted child entropy.Σ wⱼ·H(childⱼ) — also called the conditional entropy or "remainder". It is the uncertainty that is still left after you know which branch a sample fell into.
  4. Information gain. Gain = H(parent) − Σ wⱼ·H(childⱼ). This is the drop in uncertainty, and it equals the mutual information between the class and the split — which is why it can never be negative. This tool cross-checks the gain by recomputing it directly as mutual information from the joint count table.
  5. Split information and gain ratio. C4.5 adds SplitInfo = −Σ wⱼ·log₂ wⱼ, which grows with the number of branches, and GainRatio = Gain / SplitInfo. This penalises attributes with many values (a unique-ID column would otherwise win with a perfect but meaningless gain). Gain ratio is undefined when split information is 0 — only one group holds any samples.

The parent distribution is derived by summing the child columns, so you never type it separately. Switching the entropy unit from bits to nats (natural log) scales every entropy and the gain by the same factor, so the gain ratio — a ratio of two same-unit quantities — is unchanged.

Worked examples

Play Tennis, split on Outlook (Quinlan's canonical example)

  1. Children: Sunny [2,3], Overcast [4,0], Rain [3,2] → parent [9,5], N = 14
  2. H(parent) = −(9/14)log₂(9/14) − (5/14)log₂(5/14) = 0.9403 bits
  3. H(Sunny) = 0.9710, H(Overcast) = 0 (pure), H(Rain) = 0.9710
  4. Weighted = (5/14)0.9710 + (4/14)0 + (5/14)0.9710 = 0.6935
  5. Information gain = 0.9403 − 0.6935 = 0.2467 bits (textbook 0.247)
  6. Split info = 1.5774, gain ratio = 0.2467 / 1.5774 = 0.1564

Useless unique-ID split — why C4.5 needs the gain ratio

  1. Parent 2 Yes / 2 No, split on a per-row ID → four groups of 1 sample
  2. Groups [1,0], [0,1], [1,0], [0,1] — every group is pure, so H = 0
  3. Weighted child entropy = 0, so information gain = 1.0000 bit (looks perfect)
  4. Split info = −4·(1/4)log₂(1/4) = 2.0000 (four branches inflate it)
  5. Gain ratio = 1.0000 / 2.0000 = 0.5000 — far below a real split's ratio

Perfect split vs. the ID split (gain ratio breaks the tie)

  1. Parent [4,4], N = 8, H(parent) = 1.0000 bit
  2. Split gives [4,0] and [0,4]: both pure, weighted child entropy = 0
  3. Information gain = 1.0000 − 0 = 1.0000 bit (same gain as the ID split)
  4. Split info = −(0.5log₂0.5 + 0.5log₂0.5) = 1.0000 (only two branches)
  5. Gain ratio = 1.0000 / 1.0000 = 1.0000 > 0.5 — C4.5 prefers this split

Frequently asked questions

Sources & references

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.