exception:Not足够的训练实例(要求:1,提供:0)!在维卡

exception:Not enough training instances (required: 1, provided: 0)! in weka

我在文件中有一个电影数据集 moviedata.arff

@relation movie
@attribute annee numeric
@attribute Action numeric
@attribute Adventure numeric
@attribute Drama numeric
@attribute Romance numeric
@attribute Comedy numeric
@attribute Documentary numeric
@attribute Sci-Fi numeric
@attribute Triller numeric
@attribute Crime numeric
@attribute Musical numeric
@attribute Children numeric
@attribute Animation numeric
@attribute Horror numeric
@attribute Fantasy numeric
@attribute War numeric
@attribute Film-noir numeric
@attribute Western numeric
@attribute Mystery numeric
@data
%Toy Story%1995,0,1,0,0,1,0,0,0,0,0,0,1,0,1,0,0,0,0
%Jumanji%1995,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0
%Grumpier Old Men%1995,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
%Waiting to Exhale%1995,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
%Father of the Bride Part II%1995,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0
%Heat%1995,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0
%Sabrina%1995,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
%Tom and Huck%1995,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
%Sudden Death%1995,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
%GoldenEye%1995,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0
%The American President%1995,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0

我想使用 java ans weka

将此文件应用到 SimpleKmeans 算法
public class generating_clusters {  
    BufferedReader breader;
    Instances Train;

    public generating_clusters() throws Exception {
        // TODO Auto-generated constructor stub
        breader = new BufferedReader(new FileReader(
                "D:/workspace_java/JenaTutorial/moviedata.arff"));
        Train = new Instances(breader);
        SimpleKMeans kMeans = new SimpleKMeans();
        kMeans.setSeed(10);
        kMeans.setPreserveInstancesOrder(true);
        kMeans.setNumClusters(3);
        kMeans.buildClusterer(Train);
        int[] assignments = kMeans.getAssignments();
        int i = 0;
        for (int clusterNum : assignments) {
            System.out.printf("Instance %d -> Cluster %d", i, clusterNum);
            i++;
        } 
    }
}

但我有这个例外:

Exception in thread "main" weka.core.WekaException: weka.clusterers.SimpleKMeans: Not enough training instances (required: 1, provided: 0)!
    at weka.core.Capabilities.test(Capabilities.java:1400)
    at weka.core.Capabilities.test(Capabilities.java:1208)
    at weka.core.Capabilities.testWithFail(Capabilities.java:1506)
    at weka.clusterers.SimpleKMeans.buildClusterer(SimpleKMeans.java:595)
    at generating_clusters.<init>(generating_clusters.java:20)
    at generating_clusters.main(generating_clusters.java:32)

我不明白这个异常,你能帮帮我吗?

提前致谢

根据属性关系文件格式 (ARFF):

Lines that begin with a % are comments.

(http://www.cs.waikato.ac.nz/ml/weka/arff.html)

鉴于您的 moviedata.arff @data 部分,这可以解释为什么没有读入训练实例。

换句话说,当异常显示 "Not enough training instances (required: 1, provided: 0)" 时,它的意思就是字面上的意思。它认为您没有提供任何实例,因为它们都在您的 arff 文件中被注释掉了。