简体   繁体   English

Weka J48更换选项 - 没有区别

[英]Weka J48 changing option - no difference

I am trying to change options for J48 classifier, but it makes no difference in the resulted tree. 我正在尝试更改J48分类器的选项,但它在结果树中没有任何区别。

My code: 我的代码:

J48 cls = new J48();
Instances data = new Instances(new BufferedReader(new FileReader("someArffFile")));
data.setClassIndex(data.numAttributes() - 1);

//was trying to use -M 1 and -M 5, but no difference    
String[] options = new String[1];
options[0] = "-C 1.0 –M 1";     
cls.setOptions(options);

cls.buildClassifier(data);

//displaying J48 tree
TreeVisualizer tv = new TreeVisualizer(null,cls.graph(),new PlaceNode2());

After I set the value with this method then everything is working fine. 用这个方法设置值后,一切正常。

cls.setMinNumObj(5);

Any ideas how I can use setOptions method instead of setMinNumObj? 任何想法如何使用setOptions方法而不是setMinNumObj?

The problem is how you try to set the options. 问题是你如何尝试设置选项。 The options array should be like the args array in the main method, one string per element: options数组应该与main方法中的args数组类似,每个元素一个字符串:

String[] options = {"-C", "1.0", "–M", "1"};
cls.setOptions(options);

Otherwise it won't work. 否则它将无法工作。

First, options should be an array rather than a string. 首先,选项应该是数组而不是字符串。 So you can try sth as follows. 所以你可以尝试如下。

String[] options = {"-C", "1.0", "-M", "1"};
cls.setOptions(options);

More important, a small bug should be noticed carefully. 更重要的是,应该仔细注意一个小虫子。 Both in your question and in the previous answer from @Sentry, a shorter line happens before C, like "-C"; 在您的问题和@Sentry的上一个答案中,较短的一行发生在C之前,如“-C”; but a longer line happens before M, like "–M". 但是在M之前发生了更长的线,比如“-M”。

If you watch carefully, you will find that the signs before M is actually not the minus sign because it's longer than minus sign. 如果你仔细观察,你会发现M之前的标志实际上不是减号,因为它长于减号。 When you change the longer line into a really minus sign, you could get a right result by the codes above. 当您将较长的行更改为真正的减号时,您可以通过上面的代码获得正确的结果。

Good luck. 祝好运。

The best way is to utilize the splitOptions(String[] options) method of the weka.Core.Utils class : 最好的方法是使用weka.Core.Utils类的splitOptions(String[] options)方法:

String[] options = weka.core.Utils.splitOptions("-C 1.0 –M 1");
cls.setOptions(options); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM