【问题标题】:weka is able to use classification via clusteringweka 能够通过聚类使用分类
【发布时间】:2014-04-21 15:38:04
【问题描述】:

我是 WEKA 工具的新手。我可以结合分类和聚类吗?即首先对数据进行聚类,然后对实例进行聚类分类。对于此要求,需要遵循哪些步骤。

提前致谢。

【问题讨论】:

    标签: cluster-analysis classification weka


    【解决方案1】:

    是的,你可以。使用 ClassificationViaClustering 分类器 (Class ClassificationViaClustering) 真的很容易。

    Java 伪代码中的步骤:
    1. 创建一个 SimpleKMeans 聚类器

    SimpleKMeans skm = new SimpleKMeans();
    skm.setNumClusters(5); // in this example the clusterer uses 5 clusters
    

    2。读取数据集并设置类索引

    BufferedReader reader = new BufferedReader(new FileReader("[path].arff")); // replace [path] with your path to dataset
    Instances data = new Instances(reader);
    data.setClassIndex([your class index]); // if the first attribute is your class, then insert 0  
    

    3。创建分类器

    ClassifierViaClustering cvc = new ClassificationViaClustering();
    cvc.setClusterer(skm); // let your classifier use the SimpleKMeans clusterer
    cvc.buildClassifier(data);
    

    那么,当你想对一个新实例进行分类时:

    Instance instanceToClassify = new Instance(data.firstInstance());
    instanceToClassify.setDataset(data); // the instance to be classified has to have access to the dataset
    double class = cvc.classifyInstance(instanceToClassify); // classify instance based by the cluster it belongs to
    

    【讨论】:

      猜你喜欢
      • 2015-01-04
      • 1970-01-01
      • 2018-12-22
      • 2011-08-13
      • 2023-03-08
      • 2011-10-04
      • 2014-07-05
      • 2012-03-18
      • 2012-07-16
      相关资源
      最近更新 更多