mahout聚类结果的输出和可视化

1、在mahout中,org.apache.mahout.utils.clustering.ClusterDumper类可以将聚类结果输出,如果是打印在控制台,则可以使用:

 ClusterDumper clusterdumper=new ClusterDumper(sequentialfile,clusterpoints);    
 clusterdumper.printClusters(null);

其中第一个参数表示聚类结果的簇中心序列化的文件路径的path类,第二个参数表示聚类结果的中心序列化文件路径的path类


如果要输出到文件,则可以在控制台通过命令运行该ClusterDumper.java文件,如何要在eclipse中运行的话,则给ClusterDumper.java添加所需要的参数,然后run即可,参数说明如下:

--help                               Print out help 
--input (-i) input                   The directory containing Sequence
                                       Files for the Clusters   (聚类结果的序列化的簇中心文件路径)    
--output (-o) output                 The output file.  If not specified,(反序列化后的结果输出路径)
                                       dumps to the console.
--outputFormat (-of) outputFormat    The optional output format to write
                                       the results as. Options: TEXT, CSV, or GRAPH_ML       
--substring (-b) substring           The number of chars of the     
                       asFormatString() to print    
--pointsDir (-p) pointsDir           The directory containing points  
                                       sequence files mapping input vectors
                                       to their cluster.  If specified, 
                                       then the program will output the 
                                       points associated with a cluster (聚类结果的数据点序列化文件)
--dictionary (-d) dictionary         The dictionary file.
--dictionaryType (-dt) dictionaryType    The dictionary file type       
                                     (text|sequencefile)
--distanceMeasure (-dm) distanceMeasure  The classname of the DistanceMeasure.
                                           Default is SquaredEuclidean.
--numWords (-n) numWords             The number of top terms to print 
--tempDir tempDir                    Intermediate output directory
--startPhase startPhase              First phase to run
--endPhase endPhase                  Last phase to run
--evaluate (-e)                      Run ClusterEvaluator and CDbwEvaluator over the
                                      input. The output will be appended to the rest of
                                      the output at the end.
其中红色的部分参数是必须的。


2、可视化聚类结果:

在mahout源码中,org.apache.mahout.clustering.display包下有对应的可视化类,之间运行即可看到结果,是用java swing写的

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Mahout是一个基于Hadoop的机器学习库,其中包含了很多常用的机器学习算法,包括K-Means聚类算法。下面是基于Mahout实现K-Means聚类的步骤: 1. 准备数据 将需要聚类的数据准备好,以适合Mahout输入格式的方式存储,例如HDFS上的文本文件。 2. 配置Mahout 在Hadoop集群上安装Mahout,并配置好Hadoop和Mahout的环境变量。 3. 运行K-Means聚类 使用Mahout中的kmeans命令来运行K-Means聚类算法,命令格式如下: ``` mahout kmeans -i <input> -c <centroids> -o <output> -dm <distanceMeasure> -k <k> ``` 其中,参数含义如下: - input:输入数据路径 - centroids:初始质心路径 - output:输出结果路径 - distanceMeasure:距离度量方法,例如EuclideanDistanceMeasure - k:聚类数量 4. 分析结果 分析K-Means聚类的结果,可以使用Mahout中的clusterdump命令来输出聚类结果,例如: ``` mahout clusterdump -i <input> -o <output> -p <points> -d <dictionary> -dt <distanceMeasure> ``` 其中,参数含义如下: - input:聚类结果路径 - output:输出结果路径 - points:数据点路径 - dictionary:词典路径 - distanceMeasure:距离度量方法 以上是基于Mahout实现K-Means聚类的步骤,需要注意的是,Mahout的输入格式和输出格式都需要按照Mahout要求的格式进行,否则会导致运行失败。同时,在运行过程中,需要根据实际情况调整参数,以达到最佳的聚类效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值