您好我正试图从Github运行SimpleKmeanClustering代码,看看群集是如何工作的, 我能够在我的Windows Eclipse上编译代码。
我制作了一个我的项目的jar,我想在单节点Hadoop集群( CHD-4.2.1 )上运行它,并在其上安装了mahout。 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:无法添加class:jar java.lang.ClassNotFoundException:jar 在java.net.URLClassLoader $ 1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) 在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) 在org.apache.mahout.driver.MahoutDriver.addClass(MahoutDriver.java:236) 在org.apache.mahout.driver.MahoutDriver.main(MahoutDriver.java:128) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at 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 classpath,将只使用命令行参数Unknown program' jar' 选择。有效的程序名称是:arff.vector :: Generate Vectors 来自ARFF文件或目录baumwelch :: Baum-Welch算法 无人监督的HMM训练冠层::冠层聚类cat :: Print 一个文件或资源,因为逻辑回归模型会看到它 cleansvd ::清理和验证SVD输出clusterdump :: 转储集群输出到文本clusterpp :: Group Clustering Output In 集群cmdump :: HTML或文本格式的转储混淆矩阵
cvb :: LDA via Collapsed Variation Bayes(0th deriv。approx)
cvb0_local :: LDA via Collapsed Variation Bayes,在本地内存中 dirichlet :: Dirichlet聚类本征切割:: Eigencuts谱 clustering evaluateFactorization ::计算评级的RMSE和MAE 针对探针fkmeans的矩阵分解:模糊K均值 聚集fpg ::频繁模式增长hmmpredict ::生成 给定HMM项目相似性的随机观察序列: 计算基于项目的协作的项目 - 项目相似性 过滤kmeans :: K-means clustering lucene.vector :: Generate 来自Lucene索引matrixdump的向量:: CSV格式的转储矩阵 matrixmult ::取两个矩阵的乘积意味着:平均 Shift clustering minhash ::运行Minhash群集parallelALS :: 评级矩阵的ALS-WR分解推荐为: 使用评级矩阵的因子分解计算建议
recommendeditembased ::使用基于项目的计算建议 协同过滤regexconverter ::转换文本文件 每行基于正则表达式rowid :: Map SequenceFile到 {SequenceFile, SequenceFile} rowsimilarity ::计算 矩阵runAdaptiveLogistic行的成对相似性: 使用可能经过培训和验证的新生产数据进行评分 AdaptivelogisticRegression模型runlogistic ::运行逻辑 针对CSV数据的回归模型seq2encoded :: Encoded Sparse 从文本序列文件生成矢量seq2sparse ::稀疏 从文本序列文件生成矢量生成seqdirectory :: Generate 序列文件(文本)来自目录seqdumper :: Generic 序列文件转储器seqmailarchives ::从a创建SequenceFile 包含gzip压缩文件的目录seqwiki :: Wikipedia xml dump to sequence file spectralkmeans :: Spectral k-means clustering split :: split输入数据到测试和训练集splitDataset :: 将评级数据集拆分为训练和探测部分ssvd :: 随机SVD svd :: Lanczos奇异值分解testnb: :测试基于矢量的贝叶斯分类器trainAdaptiveLogistic :: 训练一个AdaptivelogisticRegression模型trainlogistic ::训练一个 使用随机梯度下降trainnb的逻辑回归: 训练基于矢量的贝叶斯分类器转置::取 矩阵的转置validateAdaptiveLogistic ::验证一个 针对保持数据集vecdist的AdaptivelogisticRegression模型: :计算一组向量(或群集或。)之间的距离 Canopy,它们必须适合内存)和矢量列表vectordump :: 将序列文件中的向量转储到文本viterbi :: 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();
}
}
任何人都可以为此指导我......
答案 0 :(得分:0)
我认为该命令应该是mahout kmeans
,而不是mahout jar
。
https://cwiki.apache.org/MAHOUT/k-means-clustering.html
你的命令很糟糕。
答案 1 :(得分: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