Solved – Converting J48 to if-then rules in Weka

cartmachine learningweka

I have a J48 decision tree model trained with WEKA. I would like to access the rules of the tree in J48 so that I can somehow use them in my code whether with if-else statements or as a decision table I can access in my code. Is this possible? If yes, how?

Best Answer

In the weka explorer, under the classify tab. Once you have chosen the J48 classifier and have clicked the start button, the classifier output displays the confusion matrix. Just under the start button there is the result list, right click the most recent classifier and look for the visualise tree option. Note that if things do not display well, you can right click the new window and select the fit to screen option.

edit: You can also save, then reuse, the model created in your code

To have the model file as a class in Java: In the weka explorer, under the classify tab. Click the button More options, and check the output source code box. Then re-run the classifier and code will be output to the Classifier output box.

Related Question