# C4.5 algorithm

C4.5 is an algorithm used to generate a decision tree developed by Ross Quinlan. C4.5 is an extension of Quinlan's earlier ID3 algorithm. The decision trees generated by C4.5 can be used for classification, and for this reason, C4.5 is often referred to as a statistical classifier. In 2011, authors of the Weka machine learning software described the C4.5 algorithm as "a landmark decision tree program that is probably the machine learning workhorse most widely used in practice to date".
It became quite popular after ranking #1 in the Top 10 Algorithms in Data Mining pre-eminent paper published by Springer LNCS in 2008.

## Algorithm

C4.5 builds decision trees from a set of training data in the same way as ID3, using the concept of information entropy. The training data is a set $S={s_{1},s_{2},...}$ of already classified samples. Each sample $s_{i}$ consists of a p-dimensional vector $(x_{1,i},x_{2,i},...,x_{p,i})$, where the $x_{j}$ represent attribute values or features of the sample, as well as the class in which $s_{i}$ falls.
At each node of the tree, C4.5 chooses the attribute of the data that most effectively splits its set of samples into subsets enriched in one class or the other. The splitting criterion is the normalized information gain (difference in entropy). The attribute with the highest normalized information gain is chosen to make the decision. The C4.5 algorithm then recurses on the partitioned sublists.
This algorithm has a few base cases.
* All the samples in the list belong to the same class. When this happens, it simply creates a leaf node for the decision tree saying to choose that class.
* None of the features provide any information gain. In this case, C4.5 creates a decision node higher up the tree using the expected value of the class.
* Instance of previously unseen class encountered. Again, C4.5 creates a decision node higher up the tree using the expected value.

### Pseudocode

In pseudocode, the general algorithm for building decision trees is:
* Check for the above base cases.
* For each attribute a, find the normalized information gain ratio from splitting on a.
* Let a_best be the attribute with the highest normalized information gain.
* Create a decision node that splits on a_best.
* Recurse on the sublists obtained by splitting on a_best, and add those nodes as children of node.

## Implementations

J48 is an open source Java implementation of the C4.5 algorithm in the Weka data mining tool.

## Improvements from ID3 algorithm

C4.5 made a number of improvements to ID3. Some of these are:
* Handling both continuous and discrete attributes - In order to handle continuous attributes, C4.5 creates a threshold and then splits the list into those whose attribute value is above the threshold and those that are less than or equal to it.
* Handling training data with missing attribute values - C4.5 allows attribute values to be marked as ? for missing. Missing attribute values are simply not used in gain and entropy calculations.
* Handling attributes with differing costs.
* Pruning trees after creation - C4.5 goes back through the tree once it's been created and attempts to remove branches that do not help by replacing them with leaf nodes.

## Improvements in C5.0/See5 algorithm

Quinlan went on to create C5.0 and See5 (C5.0 for Unix/Linux, See5 for Windows) which he markets commercially. C5.0 offers a number of improvements on C4.5. Some of these are:
* Speed - C5.0 is significantly faster than C4.5 (several orders of magnitude)
* Memory usage - C5.0 is more memory efficient than C4.5
* Smaller decision trees - C5.0 gets similar results to C4.5 with considerably smaller decision trees.
* Support for boosting - Boosting improves the trees and gives them more accuracy.
* Weighting - C5.0 allows you to weight different cases and misclassification types.
* Winnowing - a C5.0 option automatically winnows the attributes to remove those that may be unhelpful.
Source for a single-threaded Linux version of C5.0 is available under the GNU General Public License (GPL).