public static void runClassifierCV(WekaClassifier wekaClassifier, Dataset dataset)
throws Exception
{
// Set parameters
int folds = 10;
Classifier baseClassifier = ClassifierSimilarityMeasure.getClassifier(wekaClassifier);
// Set up the random number generator
long seed = new Date().getTime();
Random random = new Random(seed);
// Add IDs to the instances
AddID.main(new String[] {"-i", MODELS_DIR + "/" + dataset.toString() + ".arff",
"-o", MODELS_DIR + "/" + dataset.toString() + "-plusIDs.arff" });
Instances data = DataSource.read(MODELS_DIR + "/" + dataset.toString() + "-plusIDs.arff");
data.setClassIndex(data.numAttributes() - 1);
// Instantiate the Remove filter
Remove removeIDFilter = new Remove();
removeIDFilter.setAttributeIndices("first");
// Randomize the data
data.randomize(random);
// Perform cross-validation
Instances predictedData = null;
Evaluation eval = new Evaluation(data);
for (int n = 0; n < folds; n++)
{
Instances train = data.trainCV(folds, n, random);
Instances test = data.testCV(folds, n);
// Apply log filter
// Filter logFilter = new LogFilter();
// logFilter.setInputFormat(train);
// train = Filter.useFilter(train, logFilter);
// logFilter.setInputFormat(test);
// test = Filter.useFilter(test, logFilter);
// Copy the classifier
Classifier classifier = AbstractClassifier.makeCopy(baseClassifier);
// Instantiate the FilteredClassifier
FilteredClassifier filteredClassifier = new FilteredClassifier();
filteredClassifier.setFilter(removeIDFilter);
filteredClassifier.setClassifier(classifier);