Search code examples
javaexceptionwekadata-miningk-means

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


i l have a dataset of movie in file 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

and i want to apply a this file a SimpleKmeans algorithm using java ans weka

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++;
        } 
    }
}

but i have this exception:

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)

i don't undestand this exception, can you help me please?

Thank you in advance


Solution

  • According to the Attribute-Relation File Format (ARFF):

    Lines that begin with a % are comments.

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

    So given your moviedata.arff @data section, that could explain why there are no training instances being read in.

    In other words, when the exception says "Not enough training instances (required: 1, provided: 0)", it means it quite literally. It thinks you have not provided any instances because they are all commented out in your arff file.