【发布时间】:2013-06-02 05:41:52
【问题描述】:
您好,我正在尝试运行来自 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: 罐子 在 java.net.URLClassLoader$1.run(URLClassLoader.java:202) 在 java.security.AccessController.doPrivileged(本机方法) 在 java.net.URLClassLoader.findClass(URLClassLoader.java:190) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:306) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:247) 在 java.lang.Class.forName0(本机方法) 在 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) 在 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: No jar.props found on 类路径,将仅使用命令行参数 未知程序 'jar' 选择。有效的程序名称是: arff.vector: : 生成向量 来自 ARFF 文件或目录 baumwelch: : Baum-Welch 算法 无监督 HMM 训练树冠::树冠聚类猫::打印 逻辑回归模型会看到的文件或资源
cleansvd: : SVD 输出 clusterdump: 的清理和验证 将集群输出转储到文本 clusterpp: : Groups Clustering Output In Clusters cmdump: : 以 HTML 或文本格式转储混淆矩阵
cvb: : LDA 通过折叠变体贝叶斯(约 0 次导数)
cvb0_local: : LDA 通过折叠变体贝叶斯,在本地内存中。
dirichlet: : Dirichlet Clustering eigencuts: : Eigencuts 谱 clustering evaluateFactorization: : 计算评分的 RMSE 和 MAE 针对探针的矩阵分解 fkmeans: : Fuzzy K-means 聚类 fpg: : 频繁模式增长 hmmpredict: : 生成 给定 HMM itemsimilarity 的随机观察序列: 计算基于项目的协作的项目相似度 过滤 kmeans: : K-means 聚类 lucene.vector: : 生成 来自 Lucene 索引 matrixdump 的向量::以 CSV 格式转储矩阵 matrixmult: : 取两个矩阵的乘积 meanshift: : 均值 Shift clustering minhash: : 运行 Minhash clustering parallelALS: : 评级矩阵的 ALS-WR 分解推荐分解: 使用评级矩阵的分解计算推荐
Recommendationitembased: : 使用基于项目的计算推荐 协同过滤 regexconverter: : 转换文本文件 基于正则表达式 rowid: : Map 序列文件到 {序列文件, SequenceFile} rowsimilarity: : 计算 矩阵 runAdaptiveLogistic: 的行的成对相似性: 使用可能经过培训和验证的新生产数据评分 AdaptivelogisticRegression 模型 runlogistic: : 运行逻辑 针对 CSV 数据的回归模型 seq2encoded: : Encoded Sparse 从文本序列文件生成向量 seq2sparse: : Sparse 从文本序列文件生成向量 seqdirectory: : Generate 来自目录 seqdumper 的序列文件(文本)::通用 序列文件转储程序 seqmailarchives: : 从一个 包含压缩邮件档案的目录 seqwiki: : Wikipedia xml 转储到序列文件spectrekmeans::光谱k-means聚类 split: : 将输入数据拆分为测试集和训练集 splitDataset: : 将评级数据集拆分为训练和探测部分 ssvd: : 随机 SVD svd: : Lanczos 奇异值分解 testnb: : 测试基于向量的贝叶斯分类器 trainAdaptiveLogistic: : 训练一个 AdaptivelogisticRegression 模型 trainlogistic: : 训练一个 使用随机梯度下降的逻辑回归 trainnb: : 训练基于向量的贝叶斯分类器转置::取 矩阵的转置 validateAdaptiveLogistic: : 验证一个 针对保留数据集 vecdist 的 AdaptivelogisticRegression 模型: :计算一组向量(或簇或 Canopy,它们必须适合内存)和 Vectors 列表 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();
}
}
谁能指导我这个...
【问题讨论】:
标签: hadoop cluster-analysis classnotfoundexception mahout k-means