我在文件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)
我没有看到这个例外,你能帮帮我吗?
提前谢谢
答案 0 :(得分:1)
根据属性 - 关系文件格式(ARFF):
以%开头的行是注释。
(http://www.cs.waikato.ac.nz/ml/weka/arff.html)
所以给定你的moviedata.arff @data
部分,这可以解释为什么没有读入训练实例。
换句话说,当异常说&#34;没有足够的训练实例(必需:1,提供:0)&#34;时,它意味着它非常字面。它认为你没有提供任何实例,因为它们都在你的arff文件中被注释掉了。