J_Riccotty
12-04-2008, 10:02 AM
I am having difficulty using "setOptions(String[])" to set up a committee of classifiers.
In the enclosed code I can only get a printout of the default options. I cannot get setOptions to set anything no matter what values I try (the values are for illustration/debugging, they are not real values!)
Thank you for your help.
J R
package piacat;
// weka 3.4.13
import weka.core.*;
import weka.core.converters.*;
import weka.classifiers.meta.*;
public class HowDoI {
private static RandomCommittee BuildCommittee (){
String[] ClassifierOptions = new String[7];
// There options are not the ones I want, they are just arbitrary
// values to see if I can set them, and then print them out
ClassifierOptions[0] = "-S 27 ";
ClassifierOptions[1] = "-I 51 ";
ClassifierOptions[2] = "-W weka.classifiers.trees.RandomTree ";
ClassifierOptions[3] = "-- ";
ClassifierOptions[4] = "-K 4 ";
ClassifierOptions[5] = "-M 6.2 ";
ClassifierOptions[6] = "-S 3 ";
weka.classifiers.meta.RandomCommittee Committee = new RandomCommittee();
try {
Committee.setOptions ( ClassifierOptions );
} catch ( Exception e ) {
System.out.println ( "setOptions screw up" );
}
// No matter what values I set above, the default values are printed
PrintOptions ( Committee );
return Committee;
}
private static void PrintOptions ( RandomCommittee Committee )
{
String Opt[] = Committee.getOptions();
for ( int L=0; L<Opt.length; ++L ) {
System.out.print ( Opt[L] + " " );
}
System.out.println();
}
public static void main(String[] options) {
// Data is in a CSV (comma seperated values) file
Instances Data = null;
byte[] charArray;
CSVLoader Loader = new CSVLoader();
try {
// Read message file into string
String DataFilename = Utils.getOption('d', options);
if (DataFilename.length() != 0) {
java.io.File DataFileHandle = new java.io.File(DataFilename);
Loader.setFile(DataFileHandle);
Data = Loader.getDataSet();
// My data has a redundant attribute!
Data.deleteAttributeAt ( Data.numAttributes() - 1 );
Data.setClassIndex ( Data.numAttributes() - 1 );
} else {
throw new Exception("Name of message file not provided");
}
} catch (Exception e) {
e.printStackTrace();
}
weka.classifiers.meta.RandomCommittee
RandForest = BuildCommittee ( );
}
}
In the enclosed code I can only get a printout of the default options. I cannot get setOptions to set anything no matter what values I try (the values are for illustration/debugging, they are not real values!)
Thank you for your help.
J R
package piacat;
// weka 3.4.13
import weka.core.*;
import weka.core.converters.*;
import weka.classifiers.meta.*;
public class HowDoI {
private static RandomCommittee BuildCommittee (){
String[] ClassifierOptions = new String[7];
// There options are not the ones I want, they are just arbitrary
// values to see if I can set them, and then print them out
ClassifierOptions[0] = "-S 27 ";
ClassifierOptions[1] = "-I 51 ";
ClassifierOptions[2] = "-W weka.classifiers.trees.RandomTree ";
ClassifierOptions[3] = "-- ";
ClassifierOptions[4] = "-K 4 ";
ClassifierOptions[5] = "-M 6.2 ";
ClassifierOptions[6] = "-S 3 ";
weka.classifiers.meta.RandomCommittee Committee = new RandomCommittee();
try {
Committee.setOptions ( ClassifierOptions );
} catch ( Exception e ) {
System.out.println ( "setOptions screw up" );
}
// No matter what values I set above, the default values are printed
PrintOptions ( Committee );
return Committee;
}
private static void PrintOptions ( RandomCommittee Committee )
{
String Opt[] = Committee.getOptions();
for ( int L=0; L<Opt.length; ++L ) {
System.out.print ( Opt[L] + " " );
}
System.out.println();
}
public static void main(String[] options) {
// Data is in a CSV (comma seperated values) file
Instances Data = null;
byte[] charArray;
CSVLoader Loader = new CSVLoader();
try {
// Read message file into string
String DataFilename = Utils.getOption('d', options);
if (DataFilename.length() != 0) {
java.io.File DataFileHandle = new java.io.File(DataFilename);
Loader.setFile(DataFileHandle);
Data = Loader.getDataSet();
// My data has a redundant attribute!
Data.deleteAttributeAt ( Data.numAttributes() - 1 );
Data.setClassIndex ( Data.numAttributes() - 1 );
} else {
throw new Exception("Name of message file not provided");
}
} catch (Exception e) {
e.printStackTrace();
}
weka.classifiers.meta.RandomCommittee
RandForest = BuildCommittee ( );
}
}