Я пытаюсь построить процесс перекрестной проверки для своих конкретных проблем.Я сравнил свой код и выходные данные WEKA GUI, но есть разница между количеством правильно и неправильно классифицированных экземпляров.Мог ли я что-то пропустить?
Мой код приведен ниже (с использованием WEKA API версии 3.8.3, а также я пробовал 3.8.2 тоже):
private static void crossValidate(Instances instances, Classifier classifier, int k_value) throws Exception {
int seed = 1;
int folds = k_value;
Random rand = new Random(seed);
Instances randData = new Instances(instances);
randData.randomize(rand);
int correctlyClassified = 0;
int incorrectlyClassified = 0;
for(int n = 0; n < folds; n++) {
Instances train = randData.trainCV(folds, n, rand);
Instances test = randData.testCV(folds, n);
classifier.buildClassifier(train);
for (int t = 0; t < test.numInstances(); t++) {
Instance aTestInstance = test.instance(t);
String actualClass = test.classAttribute().value((int)aTestInstance.classValue());
String predictedClass = test.classAttribute().value((int)classifier.classifyInstance(aTestInstance));
if(actualClass.equals(predictedClass)) correctlyClassified++;
else incorrectlyClassified ++;
}
}
System.out.println("Total True is:" + correctlyClassified + "/" + incorrectlyClassified);
}