【问题标题】:The type of the expression must be an array type but it resolved to Instances表达式的类型必须是数组类型,但它解析为 Instances
【发布时间】:2021-07-24 18:28:35
【问题描述】:

我正在尝试使用 weka 构建分类器,因此我的目标是遍历我的数据并在每个实例上调用 classifyInstances。然后将预测的类值与实际的类值进行比较。统计正确预测的数量,并打印出分类器在测试数据上的准确率。

public class testMachine{
public static void main(String[] args) throws Exception {
    String arff = "C:/Users/Emil/Downloads/Week 1/Arsenal_TRAIN1.arff";
    Instances data = DatasetLoading.loadData(arff);
data.setClassIndex(data.numAttributes()-1);

NaiveBayes classifier = null;
classifier.buildClassifier(data);

double[] s = new double[0];

for(int i=0; i<data.numAttributes();i++) {
classifier.classifyInstance(data[i]);//error is here
    
}
}

虽然我收到以下错误并希望获得有关如何从此处继续的帮助:

表达式的类型必须是数组类型,但解析为实例

【问题讨论】:

    标签: java classification weka


    【解决方案1】:

    Instances是一个集合类,不是数组,不能用括号来获取元素。

    替换

    classifier.classifyInstance(data[i]);
    

    classifier.classifyInstance(data.get(i));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-20
      • 1970-01-01
      • 2012-04-20
      • 2018-08-14
      相关资源
      最近更新 更多