【问题标题】:Dumping clustering result with vectors names使用向量名称转储聚类结果
【发布时间】:2013-01-06 18:06:48
【问题描述】:

我已经按照this question 中的描述创建了我的向量,并在数据上运行了mahout kmeans

由于我使用的是 Mahout 0.7,clusterdump 命令无法按照 Mahout in Action 中的说明工作,但我让它像这样工作:

export HADOOP_CLASSPATH=/path/to/mahout-distribution-0.7/core/target/mahout-core-0.7-job.jar:/path/to/mahout-distribution-0.7/integration/target/mahout-integration-0.7.jar
hadoop jar core/target/mahout-core-0.7-job.jar org.apache.mahout.utils.clustering.ClusterDumper -i /clustering/out/clusters-20-final -o textout -of TEXT

我得到这样的台词:

VL-1383471{n=192 c=[0.180, -0.087, 0.281, 0.512, 0.678, 1.833, 2.613, 0.313, 0.226, 1.023, 0.229, -0.104, -0.461, -0.553, -0.318, 0.315, 0.658, 0.245, 0.635, 0.220, 0.660, 0.193, 0.277, -0.182, 0.497, 0.346, 0.658, 0.660, 0.191, 0.660, 0.636, 0.018, 0.519, 0.335, 0.535, 0.008, -0.028, 0.461, 0.229, 0.287, 0.619, 0.509, 0.566, 0.389, -0.075, -0.180, -0.461, 0.381, -0.108, 0.126, -0.728] r=[0.983, 0.890, 0.384, 0.823, 0.702, 0.000, 0.000, 1.132, 0.605, 0.979, 0.897, 0.862, 0.438, 0.546, 0.390, 0.171, 0.257, 0.234, 0.251, 0.106, 0.257, 0.093, 0.929, 0.077, 0.204, 0.218, 0.257, 0.257, 0.258, 0.257, 0.249, 0.112, 0.217, 0.157, 0.284, 0.197, 0.228, 0.229, 0.323, 0.401, 0.248, 0.217, 0.269, 1.002, 0.819, 0.706, 0.412, 0.964, 0.787, 0.872, 0.172]}

这对我来说还没有用,因为我需要每个集群中向量的名称。 我看到为文本文档创建了一个字典文件。如何为我的数据创建字典?

另外,使用-of CSV 给了我一个空文件,我做错了什么吗?

我的另一个尝试是直接访问cluster-20-final/part-m-00000 文件,就像在listing 7.2 of Mahout in Action 中所做的那样。结果它不包含WeightedVectorWritable,而是ClusterWritable,我可以从中得到Cluster实例,但没有任何实际包含的Vector

【问题讨论】:

    标签: cluster-analysis mahout


    【解决方案1】:

    有点晚了,但这可能会在某个时候对某个地方的人有所帮助。

    运行时

    KMeansDriver.run(input, clustersIn, outputPath, measure, convergenceDelta, maxIterations, true, 0.0, false);
    

    其中一个输出是一个名为 clusteredPoints 的目录。那里有一个零件文件,其中包含所有群集的矢量。这意味着像这样的东西

        IntWritable key = new IntWritable();
        WeightedVectorWritable value = new WeightedVectorWritable();
    
        Path clusteredPoints = new Path(output + "/" + Cluster.CLUSTERED_POINTS_DIR + "/part-m-00000");
    
        FileSystem fs = FileSystem.get(clusteredPoints.toUri(), new Configuration());
    
        try (SequenceFile.Reader reader = new SequenceFile.Reader(fs, clusteredPoints, fs.getConf())) {
    
            while (reader.next(key, value)) {
                // Do something useful here
                ((NamedVector) value.getVector()).getName();
            }
    
        } catch (Throwable t) {
            throw t;
        }
    

    似乎可以解决问题。使用类似的东西,当我使用 k-means 聚类和 Mahout 运行测试时,我能够很好地了解聚类在哪里。

    我在执行此操作时使用的是 Mahout 0.8。

    【讨论】:

    • 很抱歉碰到这样的问题,但是您可能知道为什么 clusteredPoints 中的文件是空的吗?我在 clusters-x 和 clusters-x-final 中得到了簇质心,但是 clusteredPoints 中的文件是空的。我使用了你的代码,它只是退出了 while 循环。任何帮助都会很棒。谢谢
    【解决方案2】:

    (一个非常晚的答案,但由于我花了一天时间弄清楚这个问题,所以我会分享它)

    您缺少的是向量维度名称到其索引的字典。 clusterdump 将使用该字典为您提供向量中不同维度的名称。

    运行 clusterdump 时,可以指定两个附加标志:

    • d:字典文件
    • dt:字典文件的类型(文本|序列文件)

    这是一个示例调用:

    mahout clusterdump -i clusteringExperiment/exp1/initialCentroids/clusters-0-final -d clusteringExperiment/dictionary/vectorDimensions -dt sequencefile
    

    您的输出将类似于:

    VL-0{n=185 c=[A:0.006, G:0.550, M:0.011, O:0.026, S:0.000, T:0.072, U:0.096, V:0.010] r=[A:0.029, G:0.176, M:0.043, O:0.054, S:0.001, T:0.098, U:0.113, V:0.035]}
    

    注意,字典是一个简单的键值文件,其中键是类别名称(字符串),值是数字索引。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-11
      • 2015-08-30
      • 1970-01-01
      • 2015-05-16
      • 2017-06-26
      • 1970-01-01
      • 1970-01-01
      • 2021-04-06
      相关资源
      最近更新 更多