Weka
J48
classification
data analysis
machine learning

How to interpret weka classification result J48

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

J48 in Weka is an implementation of the C4.5 decision-tree algorithm. When Weka prints the result, it is showing two different things at once: the learned tree itself and the evaluation summary for that tree. To interpret the output properly, you need to read the split rules, then connect them to the summary statistics such as correctly classified instances, confusion matrix, precision, recall, and pruning behavior.

Reading the Tree Structure

The printed tree is a set of decision rules. Each internal node tests an attribute, each branch corresponds to a condition, and each leaf predicts a class.

A simplified example might look like:

text
outlook = sunny
|   humidity <= 75: yes (10.0/2.0) |   humidity > 75: no (8.0/1.0) outlook = overcast: yes (12.0) outlook = rainy: no (9.0/1.0) ``` You read that as: - if `outlook` is `sunny` and `humidity <= 75`, predict `yes` - if `outlook` is `sunny` and `humidity > 75`, predict `no` - if `outlook` is `overcast`, predict `yes` - if `outlook` is `rainy`, predict `no` The indentation shows the path from the root to the leaf. ## What the Numbers in Leaves Mean A leaf such as: ```text yes (10.0/2.0) ``` usually means: - '`10.0` training instances reached that leaf' - '`2.0` of them were misclassified at that leaf after the final decision' So this leaf predicts `yes`, but it is not pure. Two cases reaching that leaf belonged to another class. A leaf without the second number, such as: ```text yes (12.0) ``` means all twelve training instances at that leaf were classified correctly by that rule. ## Overall Accuracy Section Weka also prints summary lines such as: - correctly classified instances - incorrectly classified instances - kappa statistic - mean absolute error - root mean squared error For a classification task, the easiest starting point is: - correctly classified percentage tells you raw accuracy - incorrectly classified percentage tells you the complement But accuracy alone can be misleading, especially with imbalanced classes. That is why the confusion matrix and per-class metrics matter. ## Confusion Matrix The confusion matrix shows how predicted classes compare with true classes. A simple binary example: ```text a  b   <-- classified as 18  2 | a = yes 4 16 | b = no ``` Interpretation: - 18 actual `yes` instances were predicted as `yes` - 2 actual `yes` instances were predicted as `no` - 4 actual `no` instances were predicted as `yes` - 16 actual `no` instances were predicted as `no` This is often more informative than overall accuracy because it shows where the model is making mistakes. ## Precision, Recall, and F-Measure Weka's detailed class metrics usually include: - precision: when the model predicts a class, how often it is correct - recall: how many actual instances of that class the model found - F-measure: harmonic mean of precision and recall These are especially important when one class matters more than another, such as fraud detection, disease prediction, or defect detection. If recall is low for a critical class, a seemingly decent overall accuracy may still hide a poor model. ## Pruning and Tree Size J48 usually prunes the tree to avoid overfitting. Weka reports information such as: - number of leaves - size of the tree A very large tree may fit training data closely but generalize poorly. A pruned smaller tree is often easier to interpret and may perform better on unseen data. That is why the printed tree is not just a curiosity. It tells you whether the model is simple, overcomplicated, or making decisions on attributes you did not expect. ## Training Set Versus Cross-Validation Always notice how the model was evaluated. If the output comes from evaluating on the training set, the numbers can look overly optimistic. If it comes from cross-validation or a held-out test set, the performance estimate is usually more trustworthy. In Weka, this distinction appears in the evaluation setup you selected before running J48. ## Common Pitfalls The most common mistake is reading the tree rules without checking the evaluation method. A beautiful tree with training-set accuracy may still generalize badly. Another mistake is focusing only on overall accuracy and ignoring the confusion matrix. That hides class-specific failures. Developers also often misread leaf counts such as `(10.0/2.0)`. The first number is the total reaching the leaf, and the second is the error count there. Finally, remember that J48 is a pruned decision tree. If the tree seems surprisingly small, that may be the pruning logic doing its job rather than missing information. ## Summary - Read the J48 output as both a rule tree and a model evaluation report. - Internal nodes are attribute tests and leaves are predicted classes. - Leaf counts such as `(10.0/2.0)` show total instances and leaf-level errors. - Use the confusion matrix and per-class metrics, not just overall accuracy. - Always interpret the results in light of how the evaluation was performed.

Course illustration
Course illustration