WEKA-将实例分配给kmeans.buildClusterer时出错 [英] WEKA - Error on assigning Instances to kmeans.buildClusterer

查看:153
本文介绍了WEKA-将实例分配给kmeans.buildClusterer时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Weka框架中还很陌生。到目前为止,我发现它非常易于使用和理解,但遇到一些我无法理解的问题。我正在尝试将csv文件中的数据集聚类。我得到了一个使用kmeans对数据集进行聚类的类,据我在Weka的Wiki( http://weka.wikispaces .com / ),该类的效果很好。唯一的问题是它正在读取一个arff文件,而我需要从一个csv文件读取。到现在为止还挺好。问题是当我将数据集中的实例分配给kmeans.buildClusterer(data)方法时。然后,我得到以下异常:

I'm pretty new in Weka framework. So far i find it pretty simple and easy to use and understand but i'm facing some problems i cannot understand. I'm trying to cluster a dataset from an csv file. I got a class that clusters the dataset using kmeans and as far as i read in the Weka's wiki (http://weka.wikispaces.com/) the class works fine. The only problem was that it was reading an arff file and i needed to read from a csv file. So far so good. The problem is when i assign the instances from the dataset to kmeans.buildClusterer(data) method. Then i get the following exception:

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
我缺少重要的东西吗?

I included the binary file: weka-dev-3.7.10 Am i missing something important?

亲切的问候

推荐答案

我终于设法回答了这个问题。事实证明,从3.7.2版开始,weka core更加紧凑,这意味着weka-dev中没有我需要的某些软件包。
解决方案很简单:将weka.jar而不是weka-dev软件包添加到类路径中。或者,也可以安装缺少的软件包 http:// weka .wikispaces.com / How + do + I + use + the + package + manager%3F

I finally managed to answer this question. It turns out that, from version 3.7.2, weka core is much more compact, meaning that some packages i need were not present in the weka-dev. The solution is simple: add to the classpath the weka.jar and not the weka-dev package. Alternatively the missing packages can also be installed http://weka.wikispaces.com/How+do+I+use+the+package+manager%3F

最诚挚的问候

这篇关于WEKA-将实例分配给kmeans.buildClusterer时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆