if(itemID < 0){
//add total
totalAmount = totalAmount + itemCosts[itemID - 1];
//increment counter
itemCounter++;
}
在这段代码中,我要求客户输入与数组中元素相对应的数字后,尝试遍历循环。但是我没有从数组中获取值,也没有获取要在代码末尾显示的总数。
答案 0 :(得分:1)
好吧,我在这里看到了一个大问题:
Evaluation eval = new Evaluation(ins); // init evaluation
rand = new Random(1);
int numFolds = 10; // 10-fold CV
ins.randomize(rand); // randomize the data
ins.stratify(numFolds); // stratify the randomized data for 10-fold CV
J48 template = new J48(); // classifier template for evaluation
//template.setOptions(...); // if further options need to be set
for (int i = 0; i < numFolds; i++) {
Instances trainData = ins.trainCV(numFolds, i, rand);
Instances testData = ins.testCV(numFolds, i);
Classifier cls = AbstractClassifier.makeCopy(template); // copy of classifier template
cls.buildClassifier(trainData);
eval.evaluateModel(cls, testData); // accumulate statistics
}
... // get results by eval.getXX(0) or eval.getXXX(1)
就在这里:
if(itemID < 0)
要运行此条件,itemID的每个值都必须为负,然后将负值传递给数组索引。 Java不支持在数组上使用负索引。如果您确实要这么做,则可能需要翻转条件:
itemCosts[itemID - 1]