Foundations to Frontier
Tests
D. Classical Machine Learning › D6 Decision Trees

C4.5 and C5.0: Gain Ratio, Continuous Features and Missing Values

C4.5 is Quinlan's successor to ID3 and for years the most widely used decision-tree learner. It fixes ID3's main gaps: gain ratio divides information gain by the split's own entropy to curb the many-values bias; continuous attributes get binary thresholds found by scanning sorted midpoints; missing values are handled with fractional cases; and the grown tree is pruned with a pessimistic error estimate. C5.0 adds boosting, misclassification costs and speed. This page covers each extension by hand and in code, the rules that make gain ratio work (average-gain filter, minimum branch sizes) and how missing values propagate at prediction time. In the exercises you implement the C4.5 split machinery; then you compare missing-value strategies when data are missing at random and when missingness itself is informative.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Making ID3 practical

Real data have temperatures, not just “hot/mild/cool”. They have sensor readings that are sometimes missing, and identifier-like columns that fool ID3. C4.5 keeps ID3’s recipe (pick the most informative question, recurse) and adds four upgrades:

  • it normalises the gain so many-valued attributes lose their unfair advantage;
  • it tries thresholds such as “temperature ≤ 58°” for continuous readings;
  • it lets examples with missing values flow down every branch in proportion;
  • it prunes the finished tree.
C4.5: finding the best cut on a continuous reading
faultok20°40°60°80°
at t = 58.0: gain 0.601 · gain ratio 0.618 · 24 | 16 known readings
best cut 53.4° (gain 0.753) · known fraction F = 1.00
Only midpoints between neighbouring values need checking: gain can change only where a reading crosses the cut. Hiding readings lowers every gain by the factor F (and the missing group adds to split information, lowering gain ratio further), so a feature that is often missing is less likely to be chosen.
Why engineers care

C4.5 produced readable, accurate rule sets from messy engineering data for decades, and C5.0 is still used in industry. Its handling of thresholds and missing values is the template every tree library follows, and knowing its assumptions explains when trees mishandle sensor dropouts.

📝 Quick check (Level 0)
0/3 answered
  1. 1. C4.5 handles a continuous attribute by…
  2. 2. Gain ratio divides gain by…
  3. 3. A case with a missing split value in C4.5…

Level 1: Beginner

★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.

The extensions by hand

Gain ratio. Split information is the entropy of the branch sizes. For outlook (5, 4, 5 of 14):

SI = −2·(5/14)·log₂(5/14) − (4/14)·log₂(4/14) = 1.061 + 0.516 = 1.577 bits.

Gain ratio = 0.247/1.577 = 0.156. A day-ID has SI = log₂ 14 = 3.807 and gain ratio 0.940/3.807 = 0.247. That is still higher, which is why C4.5 adds two rules:

  • consider only attributes whose gain is at least the average gain;
  • accept only splits where at least two branches hold at least 2 cases. The ID split fails this.

A continuous threshold. On the five sunny days the humidities are 70 (yes), 70 (yes), 85 (no), 90 (no) and 95 (no).

  • Candidate cuts are the midpoints 77.5, 87.5 and 92.5.
  • The cut at 77.5 separates yes from no perfectly. Its gain is the full entropy of the sunny subset, 0.971.
  • Only midpoints between neighbouring distinct values need checking, because gain changes only when a case crosses the cut.

Missing values. Suppose 2 of 14 humidities are missing.

  • C4.5 computes the gain on the 12 known cases and multiplies by F = 12/14.
  • When splitting, each case with a missing value goes down both branches, with weights equal to the branches’ shares of known cases (for example 0.6 and 0.4).
  • At prediction time the class distributions from all branches are blended with the same weights.

The steps in plain English:

  1. For each attribute, compute gain on the known cases (thresholds for continuous ones), scaled by F.
  2. Keep the valid splits with at least average gain, and choose the one with the highest gain ratio.
  3. Split, sending cases with missing values down every branch with fractional weights, and recurse.
  4. Prune bottom-up wherever replacing a subtree by a leaf does not raise the pessimistic error estimate.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Split information of two equal branches?
  2. 2. Candidate thresholds for values 2, 5, 9?
  3. 3. With 3 of 20 values missing, gain is multiplied by…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

C4.5 in full

Split selection. For each attribute A, compute Gain(A) = F·(H(known) − Σ size-weighted child entropy). Among valid splits with Gain(A) at least the average over attributes, choose the largest GainRatio(A) = Gain(A)/SplitInfo(A). In SplitInfo the missing cases form an extra “branch”.

Continuous attributes. Sort the values and evaluate each midpoint (C4.5 reports the largest training value not exceeding it). This costs O(n log n) per attribute per node with cumulative class counts. Later versions add an MDL-style correction, log₂(number of candidate cuts)/n, to the gain, because continuous attributes get many chances to look good (Quinlan, 1996).

Missing values.

  • Training: fractional cases, with weights multiplied down the tree.
  • Prediction: blend the leaf distributions reachable along every branch for the unknown attribute.

Pruning (error-based). At a node with N cases and E errors, estimate the error rate by the upper limit of a binomial confidence interval (confidence factor CF = 25%). Replace a subtree by a leaf, or by its most-used branch, if that does not increase the estimated errors. This is pessimistic pruning on the training data itself, with no validation set.

C5.0 additions. Boosting (trials), misclassification costs, winnowing of attributes, rule sets, and large speed and memory gains.

ID3 C4.5 CART
Criterion gain gain ratio Gini or variance
Splits multiway multiway (categorical), binary (continuous) binary
Missing values no fractional cases surrogate splits
Pruning χ² pre-pruning error-based (CF) cost-complexity + CV
🐍 Exercise 1: C4.5 split machinery
Implement weighted entropy, split information, categorical gain ratio with the minimum-branch validity rule, best threshold search for numeric attributes with missing values (F-scaled gain), a small C4.5-style tree using fractional cases, and prediction that blends branches for missing values; verify on the play-outside data.
📝 Quick check (Level 2)
0/3 answered
  1. 1. C4.5 considers gain ratio only for attributes with…
  2. 2. C4.5's pruning uses…
  3. 3. CART handles missing values with…

Level 3: Advanced

★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.

Theory

Why gain ratio needs guards. SplitInfo can be tiny when one branch holds almost every case, which makes the ratio huge for a nearly useless split. Requiring at least average gain removes such splits, and the minimum branch size removes ID-like splits. Gain ratio still prefers unbalanced splits in some cases. Kononenko (1995) and White and Liu (1994) analysed these biases, and later work favoured binary splits with statistical corrections (conditional inference trees, Hothorn et al., 2006).

Missing-data mechanisms (Rubin, 1976).

  • MCAR: missingness is unrelated to anything. Most strategies work, with some loss of efficiency.
  • MAR: missingness depends on observed variables.
  • MNAR: missingness depends on the missing value itself.

C4.5’s fractional cases implicitly assume that a case with a missing value behaves like the known cases at that node, a MAR-type assumption. Under MNAR that is wrong, and the fact of being missing is itself information. Exercise 2: with a sensor that drops out when it reads high, treating “missing” as a value beat C4.5’s fractional cases by 9 points.

Pessimistic pruning critique. The CF bound is a heuristic and has no rigorous statistical meaning (the data are not independent of the tree they built). It works reasonably in practice, but cross-validated cost-complexity pruning is better founded.

Interview questions.

  • When is “missing” informative? When the mechanism depends on the value or the situation: saturated sensors, skipped tests, safe-mode telemetry gaps. Encode a missing indicator or let the tree route missing values.
  • Why do modern libraries (XGBoost, LightGBM) learn a default direction for missing values? It lets the data decide where missing cases go, which captures MNAR effects cheaply.
📝 Quick check (Level 3)
0/3 answered
  1. 1. If a sensor drops out mostly when its value is high, the data are…
  2. 2. C4.5's fractional cases assume missing cases behave like…
  3. 3. XGBoost handles missing values by…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Missing sensor data: at random versus informative

History.

  • Quinlan’s C4.5: Programs for Machine Learning (1993) followed ID3 and its intermediate versions.
  • “Improved use of continuous attributes in C4.5” (1996) added the MDL correction for thresholds.
  • C5.0 (RuleQuest, 1997; open-sourced 2011) added boosting and costs.
  • C4.5 topped the 2008 IEEE ICDM survey of the top 10 data-mining algorithms.
  • The Weka implementation, J48, made it a default teaching and research tool.

Exercise 1.

  • Outlook has gain 0.2467 and gain ratio 0.1564.
  • A day-ID gets gain ratio 0.2470, but its split is invalid (no branch holds 2 cases).
  • On sunny days, humidity ≤ 77.5 gives gain 0.9710.
  • With 2 of 14 humidities missing, the gain on the 12 known cases is scaled by 12/14 to 0.3486. A case with unknown humidity gets the blended P(yes) = 0.534.

Exercise 2. Setup: a rule on 5 telemetry features with 5% label noise, and 30% of the key feature missing in training and test data. A depth-6 C4.5-style tree throughout, with accuracy against the noise-free rule over 10 repetitions.

Strategy MCAR MNAR (missing when high)
C4.5 fractional cases 0.906 0.834
mean imputation 0.914 0.909
drop incomplete training rows 0.912 0.842
missing as a value (sentinel) 0.910 0.925
  • Under MCAR the strategy hardly matters. All four were within 1 point.
  • Under MNAR, “missing” is itself a strong signal that x₀ is high. Strategies that let the tree isolate missing cases won: the sentinel, and also mean imputation, since every missing case gets the same value and the tree can carve it out with two thresholds.
  • Fractional cases and row deletion lost 8–9 points. Both treat missing cases as if they resembled the observed ones.
  • Lesson: before choosing a missing-value strategy, ask why the data are missing. Add explicit missing indicators when in doubt.
🐍 Exercise 2 (research): missing-value strategies under MCAR and MNAR
Simulate telemetry where the key feature is 30% missing, at random or mostly when high; train the same C4.5-style tree with fractional cases, mean imputation, dropped rows, or a missing sentinel; report test accuracy over 10 repetitions.

C4.5 in AI, robotics and aerospace

  • Diagnostic rule sets from maintenance and anomaly databases (C5.0 rule output).
  • Telemetry with dropouts: choose missing-value handling by mechanism (saturation, safe mode, link loss).
  • Feature thresholds that engineers can verify (“bus voltage ≤ 27.4 V”).
  • J48 in Weka remains a standard baseline in applied ML papers.

References

  1. J. R. Quinlan (1993). C4.5: Programs for Machine Learning. Morgan Kaufmann.
  2. J. R. Quinlan (1996). “Improved use of continuous attributes in C4.5.” Journal of Artificial Intelligence Research 4.
  3. D. B. Rubin (1976). “Inference and missing data.” Biometrika 63(3).
  4. I. Kononenko (1995). “On biases in estimating multi-valued attributes.” IJCAI.
  5. X. Wu et al. (2008). “Top 10 algorithms in data mining.” Knowledge and Information Systems 14.