C4.5 algorithm

Also known as: C4.5

On this page 7

The C4.5 algorithm is a decision tree induction method developed by Ross Quinlan in 1993 that builds a classification tree by repeatedly choosing the attribute with the highest gain ratio, then prunes the tree with a pessimistic error estimate. In machine learning, it is the direct successor of the ID3 algorithm and one of the most influential classic algorithms, often cited alongside CART as a foundation of modern tree-based models.

C4.5 extended ID3 with support for continuous attributes, missing values, attribute costs and post-pruning, and it can convert a tree into a set of readable if-then rules. Its open implementation, together with the commercial successor C5.0 and the Weka reimplementation J48, made it a standard baseline for interpretable classification in research and industry.

How C4.5 grows a decision tree

C4.5 grows a tree top-down and greedily: at each node it evaluates every candidate attribute, selects the one that best separates the classes, splits the data and recurses on each subset. Growth at a node stops when all examples share one class, when no attribute improves the split, or when a branch would contain fewer than a minimum number of cases, two by default.

The split criterion starts from information gain, the reduction in class entropy after a split. Plain information gain favors attributes with many distinct values, such as identifiers, because they create many pure but useless branches. C4.5 corrects this with the gain ratio, which divides information gain by the split information, the entropy of the partition itself.

To avoid favoring splits with tiny split information, C4.5 considers only attributes whose information gain is at least the average gain of all tested attributes, then picks the highest gain ratio among them. The table below contrasts the quantities involved.

MeasureWhat it capturesWeakness on its own
EntropyClass impurity of a nodeSays nothing about a split
Information gainImpurity reduction after a splitBiased toward many-valued attributes
Split informationEntropy of the partition sizesIgnores class labels
Gain ratioGain normalized by split informationUnstable when split information is near zero
Split measures used by C4.5

Handling continuous attributes and missing values

C4.5 handles a continuous attribute by sorting its values and testing binary thresholds between adjacent distinct values, producing tests such as “income at most 42,000”. The threshold with the best criterion becomes the split, and the same attribute may be split again lower in the tree at a different threshold.

For missing values, C4.5 uses a fractional approach. When computing gain, it uses only the cases with known values and scales the result by their proportion. When partitioning, a case with an unknown value is sent down every branch with a fractional weight proportional to branch sizes, and at prediction time the class distributions of all reached leaves are combined.

The table below summarizes how C4.5 treats the main attribute types.

Attribute typeSplit formPractical note
NominalOne branch per valueValue grouping is optional
ContinuousBinary threshold testSorting dominates training cost
Missing valueFractional case weightsNo imputation step required
Costly attributeGain adjusted by costSupported in extended settings
Attribute handling in C4.5

Pruning and rule extraction in C4.5

C4.5 applies error-based post-pruning: it grows a full tree first and then replaces subtrees with leaves, or with their most used branch, when this does not raise the estimated error. Because it estimates error on the training data, it uses a pessimistic upper confidence bound on the leaf error rate instead of the raw rate.

The confidence factor, 0.25 by default, controls pruning strength; lower values give more aggressive pruning and smaller trees. This avoids the separate validation set needed by reduced-error pruning, at the price of a statistically loose justification.

The companion program C4.5rules turns each root-to-leaf path into a rule, removes conditions that do not help accuracy and orders rule sets by class. The resulting rule list is often simpler than the tree and easier for domain experts to review.

C4.5 compared with ID3, CART and C5.0

C4.5 differs from its neighbors mainly in the split criterion, the tree shape and the pruning method. The table below places it among the classic decision tree algorithms.

AlgorithmSplit criterionTree shapePruning
ID3Information gainMultiway, nominal onlyNone
C4.5Gain ratioMultiway and binaryPessimistic error pruning
CARTGini impurity or varianceStrictly binaryCost-complexity pruning
C5.0Gain ratio refinementsMultiway and binaryImproved pruning, boosting
C4.5 and related tree algorithms

Unlike CART, C4.5 is a classification-only method and does not build regression trees. In practice, C5.0 is faster and produces smaller trees, while popular libraries such as scikit-learn implement an optimized CART rather than C4.5.

Strengths, limitations and when to use C4.5

The main strength of C4.5 is interpretability with little preprocessing: it needs no feature scaling, handles mixed attribute types and missing values natively, and produces models that people can audit line by line.

  • High variance: small changes in data can produce a very different tree.
  • Lower accuracy than ensembles: random forests and gradient boosting usually win on tabular benchmarks.
  • Axis-parallel splits: diagonal decision boundaries need many nodes.
  • Fragmentation: deep trees leave few cases per leaf, which weakens estimates.

C4.5 is a sound choice when explainability outweighs a few points of accuracy, for example in credit rules, clinical triage aids or teaching. When accuracy dominates, its trees work better as building blocks inside ensembles than as standalone models.

Stripped to the essentials

C4.5 builds a tree of yes-or-no questions. Each question splits the data into smaller groups. The program picks the question that best separates the answers. It repeats this until the groups are clear.

Then it cuts away branches that only fit odd cases. The final tree is like a flowchart that anyone can follow. You start at the top, answer each question, and reach a decision at the bottom.

Where it is applied

A regional hospital wants a transparent triage aid for deciding which emergency patients need urgent lab tests. Clinicians insist on a model they can read, so the data team trains C4.5 on 18,000 past visits with attributes such as age, heart rate, temperature and reported symptoms. About 12 percent of records have missing vital signs, which C4.5 handles without imputation.

With a confidence factor of 0.25 and a minimum of 20 cases per leaf, the pruned tree has 31 leaves and a depth of six. It reaches roughly 84 percent accuracy on a held-out year of data, a few points below a gradient boosting model. The hospital adopts the tree because senior physicians can review every rule and reject two that conflict with clinical guidelines before deployment.