在kmeanclustering中找不到类异常--mahout

yftpprvb  于 2021-06-04  发布在  Hadoop
关注(0)|答案(2)|浏览(358)

嗨,我正在试着运行simplekmeanclustering代码,从github来看看集群是如何工作的,我能够在我的windows eclipse上编译代码。
我为我的项目制作了一个jar,我想在一个单节点hadoop集群(chd-4.2.1)上运行它,并在其上安装mahout。mahout示例在这个集群上运行良好,因此没有安装问题。
我在command promt中使用下面的命令来运行我的jar,我不确定我的尝试是否正确。
user@infph01463u用法:~$mahout jar/home/user/apurv/kmean.jar tryout.simplekmeansclustering
我得到了相应的错误
未设置mahout\u local;正在将hadoop\ conf\ dir添加到类路径。在hadoop上运行,使用/usr/lib/hadoop/bin/hadoop和hadoop\u conf\u dir=/etc/hadoop/conf mahout job:/usr/lib/mahout/mahout-examples-0.7-cdh4.3.0-job.jar 13/06/06 14:42:18警告driver.mahoutdriver:无法添加类:jar java.lang.classnotfoundexception:jar at java.net.urlclassloader$1.run(urlclassloader)。java:202)在java.net.urlclassloader.findclass(urlclassloader)中的java.security.accesscontroller.doprivileged(本机方法)。java:190)在java.lang.classloader.loadclass(classloader。java:306)在java.lang.classloader.loadclass(classloader。java:247)在java.lang.class.forname0(本机方法)在java.lang.class.forname(类。java:169)在org.apache.mahout.driver.mahoutdriver.addclass(mahoutdriver。java:236)在org.apache.mahout.driver.mahoutdriver.main(mahoutdriver。java:128)在sun.reflect.nativemethodaccessorimpl.invoke0(本机方法)在sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl)。java:39)在sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl。java:25)在java.lang.reflect.method.invoke(方法。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::generate vectors from a arff file or directory baumwelch::baum welch algorithm for unsupervised hmm training canopy::canopy clustering cat::打印logistic回归模型将看到的文件或资源
cleansvd::svd output clusterdump::dump cluster output to text clusterpp::groups clustering output in clusters cmdump::dump html或文本格式的混淆矩阵的清理和验证
cvb::lda通过折叠的变异贝叶斯(第0阶导数)。近似值)
cvb0\u local::lda通过折叠的变异贝叶斯,在内存中本地执行。
dirichlet::dirichlet聚类eigencuts::eigencuts谱聚类evaluatefactorization::计算评级矩阵因式分解的rmse和mae fkmeans::模糊k均值聚类fpg::频繁模式增长hmm预测::根据给定的hmm项生成随机观察序列相似度::计算基于项目的协同过滤的项目相似性kmeans::k-means clustering lucene.vector::从lucene索引矩阵dump::csv格式的dump矩阵生成向量matrixmult::取两个矩阵的乘积meanshift::meanshift clustering minhash::run minhash clustering parallels::als wr factoriation of a ratingmatrix recommendfactorized::使用评级矩阵的因式分解计算建议
recommenditembased::使用基于项目的协作筛选计算建议regexconverter::基于正则表达式按行转换文本文件rowid::将sequencefileMap到{sequencefile,sequencefile}行相似度::计算矩阵行的成对相似度runadaptivelogistic::使用可能经过训练和验证的AdaptiveLogistic回归模型为新生产数据打分runlogistic::针对csv数据运行logistic回归模型seq2encoded::从文本序列文件生成编码的稀疏向量seq2sparse::从文本序列文件生成稀疏向量seqdirectory::从目录生成序列文件seqdumper::通用序列文件dumper seqmailarchives::从包含gzip邮件存档的目录创建序列文件seqwiki::wikipedia xml转储到序列文件spectralkmeans::spectral k-means聚类拆分::将输入数据拆分为测试集和训练集拆分数据集::将评级数据集拆分为训练和探测部分ssvd::随机svd svd::lanczos奇异值分解测试NB::测试基于向量的贝叶斯分类器trainadaptivelogistic::训练自适应回归模型trainlogistic::训练logistic使用随机梯度下降的回归trainnb::训练基于向量的贝叶斯分类器转置::对矩阵进行转置validateadaptivelogistic::根据保持数据集vecdist::计算一组向量(或簇或树冠)之间的距离,它们必须适合内存)和向量列表vectordump::将序列文件中的向量转储到文本viterbi::viterbi解码给定输出状态的隐藏状态序列13/06/06 14:42:18 info driver.mahoutdriver:程序耗时2毫秒(分钟:3.3335E-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();  
    }
}

有谁能给我指点一下。。。

zujrkrfu

zujrkrfu1#

我认为命令应该是 mahout kmeans ,不是 mahout jar .
https://cwiki.apache.org/mahout/k-means-clustering.html
你的命令不好。

bfrts1fy

bfrts1fy2#

你的命令根本不运行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

相关问题