楼主: ReneeBK
1130 0

[Rapidminer]How to Get Rules from a Decision Tree? [推广有奖]

  • 1关注
  • 62粉丝

VIP

已卖:4898份资源

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49640 个
通用积分
55.8137
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57805 点
帖子
4005
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

楼主
ReneeBK 发表于 2017-4-3 07:52:59 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
How to Get Rules from a Decision Tree?by mschmitz on 10-21-2016 09:53 AM - edited on 11-03-2016 07:35 AM by stevefarr


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.

  1. import com.rapidminer.operator.learner.rules.RuleModel;
  2. import com.rapidminer.tools.Ontology;
  3. import com.rapidminer.tools.LogService;
  4. import com.rapidminer.operator.learner.rules.Rule;

  5. import java.util.logging.Level
  6. RuleModel ruleModel = input[0]
  7. numberOfAttributes = 4;

  8. Attribute[] attributes= new Attribute[numberOfAttributes];
  9. attributes[0] = AttributeFactory.createAttribute("Full Rule", Ontology.STRING);
  10. attributes[1] = AttributeFactory.createAttribute("Label", Ontology.STRING);
  11. attributes[2] = AttributeFactory.createAttribute("Correct Examples covered by this rule", Ontology.STRING);
  12. attributes[3] = AttributeFactory.createAttribute("Wrong Examples covered by this rule", Ontology.STRING);
  13. MemoryExampleTable table = new MemoryExampleTable(attributes);
  14. DataRowFactory ROW_FACTORY = new DataRowFactory(0);

  15. String[] myvalues = new String[numberOfAttributes]

  16. for(Rule currentRule : ruleModel.getRules()){
  17.     int correct = 0;
  18.     int wrong = 0;
  19.     int label = ruleModel.getLabel().getMapping().getIndex(currentRule.getLabel());
  20.     LogService.root.log(Level.INFO, currentRule.toString())
  21.     int[] frequencies = currentRule.getFrequencies();
  22.     if (frequencies != null) {
  23.         for (int i = 0; i < frequencies.length; i++) {
  24.             if (i == label) {
  25.                 correct += frequencies[i];
  26.             } else {
  27.                 wrong += frequencies[i];
  28.           }
  29.       }
  30.       myvalues[0] = currentRule.toString()
  31.       myvalues[1] = currentRule.getLabel()
  32.       myvalues[2] = String.valueOf(correct);
  33.       myvalues[3] = String.valueOf(wrong);

  34.       DataRow row = ROW_FACTORY.create(myvalues, attributes)
  35.       table.addDataRow(row);
  36.     }
  37. }

  38. return table.createExampleSet();
复制代码


The result looks like the screen shot below:




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:RapidMiner Decision DMINE Rapid Rules understand Community following provides convert

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-10 19:15