我在Weka框架中很新。到目前为止,我发现它非常简单易用,易于理解,但我遇到了一些我无法理解的问题。我正在尝试从csv文件中聚类数据集。我有一个使用kmeans聚类数据集的类,就我在Weka的wiki(http://weka.wikispaces.com/)中读到的那样,该类工作正常。唯一的问题是它正在读取一个arff文件,我需要从csv文件中读取。到现在为止还挺好。问题是当我将数据集中的实例分配给kmeans.buildClusterer(data)方法时。然后我得到以下例外:
Exception in thread "main" java.lang.NoClassDefFoundError: org/pentaho/packageManagement/PackageManager
at weka.core.WekaPackageManager.<clinit>(WekaPackageManager.java:86)
at weka.core.Utils.readProperties(Utils.java:142)
at weka.core.Capabilities.<init>(Capabilities.java:261)
at weka.clusterers.AbstractClusterer.getCapabilities(AbstractClusterer.java:179)
at weka.clusterers.SimpleKMeans.getCapabilities(SimpleKMeans.java:289)
at weka.clusterers.SimpleKMeans.buildClusterer(SimpleKMeans.java:441)
at weka_examples.ClusteringDemo.<init>(ClusteringDemo.java:48)
at weka_examples.ClusteringDemo.main(ClusteringDemo.java:70)
Caused by: java.lang.ClassNotFoundException: org.pentaho.packageManagement.PackageManager
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 8 more
Java Result: 1
代码如下:
import weka.core.Instances;
import weka.clusterers.DensityBasedClusterer;
import weka.clusterers.ClusterEvaluation;
import java.io.File;
import weka.clusterers.SimpleKMeans;
import weka.core.converters.CSVLoader;
/**
* An example class that shows the use of Weka clusterers from Java.
*
* @author FracPete
*/
public class ClusteringDemo {
/**
* Run clusterers
*
* @param filename the name of the ARFF file to run on
*/
public ClusteringDemo(String filename) throws Exception {
ClusterEvaluation eval;
Instances data;
String[] options;
DensityBasedClusterer cl;
String Origem = filename;
// data = new Instances(new BufferedReader(new FileReader(filename)));
// load CSV
CSVLoader loader = new CSVLoader();
loader.setSource(new File(Origem));
data = loader.getDataSet();
SimpleKMeans kmeans = new SimpleKMeans();
kmeans.setSeed(10);
// This is the important parameter to set
kmeans.setPreserveInstancesOrder(true);
kmeans.setNumClusters(5);
kmeans.buildClusterer(data);
// This array returns the cluster number (starting with 0) for each instance
// The array has as many elements as the number of instances
int[] assignments = kmeans.getAssignments();
int i = 0;
for (int clusterNum : assignments) {
System.out.printf("Instance %d -> Cluster %d", i, clusterNum);
i++;
}
}
/**
* usage: ClusteringDemo arff-file
*/
public static void main(String[] args) throws Exception {
/*if (args.length != 1) {
System.out.println("usage: " + ClusteringDemo.class.getName() + " <arff-file>");
System.exit(1);
}*/
new ClusteringDemo("Teste/Query1.csv");
}
}
我包含了二进制文件:weka-dev-3.7.10 我错过了重要的事情吗?
亲切的问候
答案 0 :(得分:3)
我终于设法回答了这个问题。事实证明,从版本3.7.2开始,weka核心更紧凑,这意味着我需要的一些软件包不存在于weka-dev中。 解决方案很简单:将类路径添加到weka.jar而不是weka-dev包。或者,也可以安装缺少的包http://weka.wikispaces.com/How+do+I+use+the+package+manager%3F
祝你好运