The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here
How to Get Rules from a Decision Tree?
MartinLiebig
Administrator, Moderator, Employee-RapidMiner, RapidMiner Certified Analyst, RapidMiner Certified Expert, University Professor Posts: 3,533 RM Data Scientist
Question
Decision Trees are well known for their understandability. How can I get the rules a Decision Tree provides in a more handy format?
Answer
To convert Decision Trees into Rules you can use the Tree to Rule operator. The Tree to Rule operator is a nested operator, means you can put the Decision Tree inside.
The Decision Tree is parsed into a rule format which is easier to understand
This Rule Model can be parsed into a example set with the following Groovy script. The Groovy script needs to be used in an Execute Script operator. An example is attached as a process.
import com.rapidminer.operator.learner.rules.RuleModel;
import com.rapidminer.tools.Ontology;
import com.rapidminer.tools.LogService;
import com.rapidminer.operator.learner.rules.Rule;
import java.util.logging.Level
RuleModel ruleModel = input[0]
numberOfAttributes = 4;
Attribute[] attributes= new Attribute[numberOfAttributes];
attributes[0] = AttributeFactory.createAttribute("Full Rule", Ontology.STRING);
attributes[1] = AttributeFactory.createAttribute("Label", Ontology.STRING);
attributes[2] = AttributeFactory.createAttribute("Correct Examples covered by this rule", Ontology.STRING);
attributes[3] = AttributeFactory.createAttribute("Wrong Examples covered by this rule", Ontology.STRING);
MemoryExampleTable table = new MemoryExampleTable(attributes);
DataRowFactory ROW_FACTORY = new DataRowFactory(0);
String[] myvalues = new String[numberOfAttributes]
for(Rule currentRule : ruleModel.getRules()){
int correct = 0;
int wrong = 0;
int label = ruleModel.getLabel().getMapping().getIndex(currentRule.getLabel());
LogService.root.log(Level.INFO, currentRule.toString())
int[] frequencies = currentRule.getFrequencies();
if (frequencies != null) {
for (int i = 0; i < frequencies.length; i++) {
if (i == label) {
correct += frequencies[i];
} else {
wrong += frequencies[i];
}
}
myvalues[0] = currentRule.toString()
myvalues[1] = currentRule.getLabel()
myvalues[2] = String.valueOf(correct);
myvalues[3] = String.valueOf(wrong);
DataRow row = ROW_FACTORY.create(myvalues, attributes)
table.addDataRow(row);
}
}
return table.createExampleSet();
The result looks like the screen shot below:
- Sr. Director Data Solutions, Altair RapidMiner -
Dortmund, Germany
Dortmund, Germany
Tagged:
4
Comments
How to predict using Support Vector Machine? I am new here.
Hi @fatinharun94 check out our tutorial process comes with RapidMiner Studio.
http://docs.rapidminer.com/studio/operators/modeling/predictive/support_vector_machines/support_vector_machine.html
Thank you for the link. I just got the solution.
This is what i understand from the link. Is this correct?