Variant Weka J48 - no difference

I am trying to change the parameters for the J48 classifier, but this does not make any difference in the given tree.

My code is:

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 using this method, everything works fine.

 cls.setMinNumObj(5); 

Any ideas how I can use the setOptions method instead of setMinNumObj?

+4
source share
3 answers

The problem is how you are trying to set the parameters. The options array should be like the args array in the main method, one line for each element:

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

Otherwise it will not work.

0
source

First, the parameters must be an array, not a string. So you can try sth as follows.

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

More importantly, a small error should be noticed carefully. In both your question and the previous answer from @Sentry, the shorter line comes before C, for example "-C"; but before M there is a longer line, for example "-M".

If you follow closely, you will find that the signs before M are not really minus signs because it is longer than the minus sign. When you change a longer line to a minus sign, you can get the correct result from the codes above.

Good luck.

0
source

The best way is to use the splitOptions(String[] options) method of splitOptions(String[] options) class:

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

All Articles