I am trying to use a Weka method, crossValidateModel, which is posted in the last. It looks like that the fifth parameter is referred to as varargs parameter. I tried the example usage given in Weka page, such as
eval.crossValidateModel(cls, data, folds, rand);
It works just fine on one system,(eclipse+Ubuntu); but it fails on other system (RedHat Eclipse+Centos). The Eclipse gives the following message
The method crossValidateModel(Classifier, Instances, int, Random, Object[]) in the type Evaluation is not applicable for the arguments (Classifier, Instances, int, Random)
I think this problem comes from the existence of varargs parameter, but I do not know why. Thanks for the explanation.
/**
* Performs a (stratified if class is nominal) cross-validation
* for a classifier on a set of instances. Now performs
* a deep copy of the classifier before each call to
* buildClassifier() (just in case the classifier is not
* initialized properly).
*
* @param classifier the classifier with any options set.
* @param data the data on which the cross-validation is to be
* performed
* @param numFolds the number of folds for the cross-validation
* @param random random number generator for randomization
* @param forPredictionsPrinting varargs parameter that, if supplied, is
* expected to hold a weka.classifiers.evaluation.output.prediction.AbstractOutput
* object
* @throws Exception if a classifier could not be generated
* successfully or the class is not defined
*/
public void crossValidateModel(Classifier classifier,
Instances data, int numFolds, Random random,
Object... forPredictionsPrinting) throws Exception {
// Make a copy of the data we can reorder
data = new Instances(data);
data.randomize(random);
if (data.classAttribute().isNominal()) {
data.stratify(numFolds);
}
// We assume that the first element is a
// weka.classifiers.evaluation.output.prediction.AbstractOutput object
AbstractOutput classificationOutput = null;
if (forPredictionsPrinting.length > 0) {
// print the header first
classificationOutput = (AbstractOutput) forPredictionsPrinting[0];
classificationOutput.setHeader(data);
classificationOutput.printHeader();
}
// Do the folds
for (int i = 0; i < numFolds; i++) {
Instances train = data.trainCV(numFolds, i, random);
setPriors(train);
Classifier copiedClassifier = AbstractClassifier
.makeCopy(classifier);
copiedClassifier.buildClassifier(train);
Instances test = data.testCV(numFolds, i);
evaluateModel(copiedClassifier, test,
forPredictionsPrinting);
}
m_NumFolds = numFolds;
if (classificationOutput != null)
classificationOutput.printFooter();
}