0

嗨,我正在尝试从 Github 运行SimpleKmeanClustering代码以查看集群的工作原理,我能够在我的 Windows Eclipse 上编译代码。

我为我的项目制作了一个 jar,我想在安装了 mahout 的单节点 Hadoop 集群(CHD-4.2.1)上运行它。mahout 示例在此集群上运行良好,因此没有安装问题。

我在命令 Promt 中使用以下命令来运行我的 jar,我不确定我是否以正确的方式尝试。

user@INFPH01463U:~$ mahout jar /home/user/apurv/Kmean.jar tryout.SimpleKMeansClustering

我得到了相应的错误

MAHOUT_LOCAL 未设置;将 HADOOP_CONF_DIR 添加到类路径。在 hadoop 上运行,使用 /usr/lib/hadoop/bin/hadoop 和 HADOOP_CONF_DIR=/etc/hadoop/conf MAHOUT-JOB:/usr/lib/mahout/mahout-examples-0.7-cdh4.3.0-job.jar 13/ 06/06 14:42:18 WARN driver.MahoutDriver: 无法添加类: jar java.lang.ClassNotFoundException: jar at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged (Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at org.apache.mahout.driver.MahoutDriver.addClass(MahoutDriver. java:236) 在 org.apache.mahout.driver.MahoutDriver.main(MahoutDriver.java:128) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在 java.lang.reflect.Method.invoke(Method.java:597) 在 org.apache.hadoop.util.RunJar.main(RunJar.java:208 ) 13/06/06 14:42:18 WARN driver.MahoutDriver:在类路径上找不到 jar.props,将仅使用命令行参数选择未知程序“jar”。有效的程序名称是: arff.vector: : 从 ARFF 文件或目录生成向量 baumwelch: : 用于无监督 HMM 训练树冠的 Baum-Welch 算法: : Canopy clustering cat: :
cleansvd: : SVD 输出的清理和验证 clusterdump: : 将集群输出转储到文本 clusterpp: : 集群中的集群输出 cmdump: : 以 HTML 或文本格式转储混淆矩阵
cvb: : LDA 通过折叠变体贝叶斯 (0th deriv. 大约)
cvb0_local: : LDA 通过折叠变体贝叶斯,在本地内存中。
dirichlet: : Dirichlet Clustering eigencuts: : Eigencuts 谱聚类 evaluateFactorization: : 计算针对探针 fkmeans 的评级矩阵分解的 RMSE 和 MAE: : Fuzzy K-means clustering fpg: : 频繁模式增长 hmmpredict: : 通过给定的 HMM 生成随机观察序列itemsimilarity: : 计算基于项目的协同过滤的 item-item-similarities kmeans: : K-means clustering lucene.vector: : 从 Lucene 索引生成向量 matrixdump: : 以 CSV 格式转储矩阵 matrixmult: : 取两个的乘积矩阵 meanshift: : Mean Shift clustering minhash: : 并行运行 Minhash 聚类ALS: : 评级矩阵的 ALS-WR 分解推荐因子化: : 使用评级矩阵的分解计算推荐
Recommendationitembased: : 使用基于项目的协同过滤计算推荐 regexconverter: : 基于正则表达式逐行转换文本文件 rowid: : 将 SequenceFile 映射到 {SequenceFile, SequenceFile} rowsimilarity: : 计算矩阵行的成对相似度runAdaptiveLogistic: : 使用可能经过训练和验证的 AdaptivelogisticRegression 模型对新生产数据进行评分 runlogistic: : 针对 CSV 数据运行逻辑回归模型 seq2encoded: : 从文本序列文件生成编码稀疏向量 seq2sparse: : 从文本序列文件生成稀疏向量 seqdirectory: :从目录 seqdumper: 生成序列文件 (文本): : Generic Sequence File dumper seqmailarchives: :从包含 gzip 压缩邮件存档的目录创建 SequenceFile seqwiki: : Wikipedia xml 转储到序列文件spectralkmeans: : Spectral k-means clustering split: : Split Input data into test and train sets splitDataset: : split a rating dataset into training and probe part ssvd : : 随机 SVD svd: : Lanczos 奇异值分解 testnb: : 测试基于向量的贝叶斯分类器 trainAdaptiveLogistic: : 训练自适应逻辑回归模型 trainlogistic: : 使用随机梯度下降训练逻辑回归 trainnb: : 训练基于向量的贝叶斯分类器转置:: 对矩阵进行转置 validateAdaptiveLogistic: : 根据保留数据集 vecdist: 验证 AdaptivelogisticRegression 模型:计算一组向量(或集群或 Canopy,它们必须适合内存)与向量列表之间的距离 vectordump: : 将向量从序列文件转储到文本 viterbi: : 给定输出状态序列 13 的隐藏状态的维特比解码/06/06 14:42:18 INFO driver.MahoutDriver:程序耗时 2 毫秒(分钟:3.3333333333333335E-5)

这是我正在使用的代码:

代码

package tryout;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text;
import org.apache.mahout.math.RandomAccessSparseVector;
import org.apache.mahout.math.Vector;
import org.apache.mahout.math.VectorWritable;
import org.apache.mahout.clustering.kmeans.Kluster;
import org.apache.mahout.clustering.classify.WeightedVectorWritable;
import org.apache.mahout.clustering.kmeans.KMeansDriver;
import org.apache.mahout.common.distance.EuclideanDistanceMeasure;

public class SimpleKMeansClustering {
    public static final double[][] points = { {1, 1}, {2, 1}, {1, 2}, 
                                              {2, 2}, {3, 3}, {8, 8},
                                              {9, 8}, {8, 9}, {9, 9}};    


    public static void writePointsToFile(List<Vector> points,
            String fileName,FileSystem fs,Configuration conf) throws IOException {    
        Path path = new Path(fileName);    
        @SuppressWarnings("deprecation")
        SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf,path, LongWritable.class, VectorWritable.class);    

        long recNum = 0;    
        VectorWritable vec = new VectorWritable();    
        for (Vector point : points) {       
         vec.set(point);      
          writer.append(new LongWritable(recNum++), vec);    
        }    writer.close();  
    }    

    public static List<Vector> getPoints(double[][] raw) {    
        List<Vector> points = new ArrayList<Vector>();    
        for (int i = 0; i < raw.length; i++) {      
            double[] fr = raw[i];      
            Vector vec = new RandomAccessSparseVector(fr.length);      
            vec.assign(fr);      
            points.add(vec);    
        }    
        return points;  
    }    
    public static void main(String args[]) throws Exception {        
        int k = 2;        
        List<Vector> vectors = getPoints(points);        
        File testData = new File("testdata");    
        if (!testData.exists()) {      
            testData.mkdir();    
        }    
        testData = new File("testdata/points");    
        if (!testData.exists()) {      
            testData.mkdir();    
        }        
        Configuration conf = new Configuration();    
        FileSystem fs = FileSystem.get(conf);    
        writePointsToFile(vectors, "testdata/points/file1", fs, conf);        
        Path path = new Path("testdata/clusters/part-00000");    
        @SuppressWarnings("deprecation")
        SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf,path, Text.class, Kluster.class);
        for (int i = 0; i < k; i++) {      
            Vector vec = vectors.get(i);      
            Kluster cluster = new Kluster(vec, i, new EuclideanDistanceMeasure());      
            writer.append(new Text(cluster.getIdentifier()), cluster);    
        }    
        writer.close();        

        KMeansDriver.run(conf, new Path("testdata/points"), new Path("testdata/clusters"),      
                new Path("output"), new EuclideanDistanceMeasure(), 0.001, 10,
                true,0.0, false);        
        @SuppressWarnings("deprecation")
        SequenceFile.Reader reader = new SequenceFile.Reader(fs,new Path("output/" + Kluster.CLUSTERED_POINTS_DIR+ "/part-m-00000"), conf);        
        IntWritable key = new IntWritable();   
        WeightedVectorWritable value = new WeightedVectorWritable();    
        while (reader.next(key, value)) {      
            System.out.println(value.toString() + " belongs to cluster " + key.toString());    
        }    
        reader.close();  
    }
}

谁能指导我这个...

4

2 回答 2

0

您的命令根本不运行 kmeans。你需要运行这样的东西:

./bin/mahout kmeans -i reuters-vectors/tfidf-vectors/ -o mahout-clusters -c mahout-initial-centers -c 0.1 -k 20 -x 10 -ow

请参考以下链接:https ://mahout.apache.org/users/clustering/k-means-clustering.html

于 2014-10-30T00:29:11.533 回答
0

我相信命令应该读mahout kmeans,而不是mahout jar

https://cwiki.apache.org/MAHOUT/k-means-clustering.html

你的命令很糟糕。

于 2013-06-06T09:22:49.283 回答