java - 堆栈跟踪 : weka. core.WekaException : weka. classifiers.functions.SMO : Not enough training instances with class labels (required: 1, 提供 : 0)!

标签 java weka

当我尝试打印实例数时,它显示为 0(零)。但是当我使用 Weka API 手动选择 ARFF 文件时,我的训练数据中有 565 个实例。我想找出错误所在。谢谢。

private static void build_model() {
            // TODO Auto-generated method stub
            try{

            // load data    
            ArffLoader loader = new ArffLoader();
            loader.setFile(new File("D:\\MAIN PROJECT\\data.arff"));
            Instances structure = loader.getStructure();
            structure.setClassIndex(structure.numAttributes() - 1);
            System.out.println("Attributes : "+structure.numAttributes());
            System.out.println("Instances : "+structure.numInstances());

            // train SMO
            System.out.println("Before creating smo object");
            SMO smo = new SMO();
            System.out.println("SMO object created");
            smo.buildClassifier(structure);
            System.out.println("Classifier build");
            Instance current;
            while ((current = loader.getNextInstance(structure)) != null){
                smo.buildClassifier((Instances) current);
            }
            System.out.println(smo);
            System.out.println("\nModel build successfully");
            }
            catch(Exception e){
                System.out.println("\nstack trace : " + e);
            }

        }

输出:

属性:1154 实例:0 创建 smo 对象之前 创建 SMO 对象

堆栈跟踪:weka.core.WekaException:weka.classifiers.functions.SMO:没有足够的带有类标签的训练实例(必需:1,提供:0)!

最佳答案

尝试使用getDataSet()而不是getStructure()

关于java - 堆栈跟踪 : weka. core.WekaException : weka. classifiers.functions.SMO : Not enough training instances with class labels (required: 1, 提供 : 0)!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15461261/

相关文章:

Java Swing : how to get the color of a pixel of a JFrame

java - 如何使用 double 格式的数字为范围之间的随机间隔编写代码?

java - 如何替换 url 中的 unicode 字符串以获得 json 响应?

java - Weka Example,文本行的简单分类

java - 使用 weka api 进行聚类

java - 在 Java 应用程序中包含 GIT 安装

java - 我可以使用 Fitbit Api 获取我的 Fitbit 的加速度数据吗?

java - 使用 weka arff 文件中的标签对数据集进行索引

machine-learning - Weka 可以处理多少文本?

Java Weka获取具有给定属性值的所有实例