java 调用 mahout_(转)Mahout使用入门
一、简介
Mahout 是 Apache Software Foundation(ASF)旗下的一个开源项目,提供一些可扩展的机器学习领域经典算法的实现,旨在帮助开发人员更加方便快捷地创建智能应用程序。Apache Mahout项目已经发展到了它的第三个年头,目前已经有了三个公共发行版本。Mahout包含许多实现,包括集群、分类、推荐过滤、频繁子项挖掘。此外,通过使用 Apache Hadoop 库,Mahout 可以有效地扩展到云中。
二、下载与准备
程序下载
下载hadoop http://labs.renren.com/apache-mirror/hadoop/common/下载适合版本的包(本文采用稳定版 hadoop-0.20.203.0rc1.tar.gz )
(本文采用mahout-distribution-0.5.tar.gz)
如需更多功能可能还需下载 maven 和 mahout-collections
数据下载
(本文使用synthetic_control 数据,synthetic_control.tar.gz)
三、安装与部署
为了不污染Linux root环境,本文采用在个人Home目录安装程序,程序目录为$HOME/local。
程序已经下载到$HOME/Downloads,使用tar命令解压:
tar zxvf hadoop-0.20.203.0rc1.tar.gz -C ~/local/
cd ~/local
mv hadoop-0.20.203.0 hadoop
tar zxvf mahout-distribution-0.5.tar.gz -C ~/local/
cd ~/local
mv mahout-distribution-0.5 mahout
修改.bash_profile / .bashrc
export HADOOP_HOME=$HOME/local/hadoop
export HADOOP_CONF_DIR=$HADOOP_HOME/conf
为方便使用程序命令,可把程序bin目录添加到$PATH下,或者直接alias 。
#Alias for apps
alias mahout=’$HOME/local/mahout/mahout’
alias hdp=’$HOME/local/hadoop/hdp’
测试
输入命令: mahout
预期结果:
Running on hadoop, using HADOOP_HOME=/home/username/local/hadoop
HADOOP_CONF_DIR=/home/username/local/hadoop/conf
An example program must be given as the first argument.
Valid program names are:
arff.vector: : Generate Vectors from an ARFF file or directory
canopy: : Canopy clustering
cat: : Print a file or resource as the logistic regression models would see it
cleansvd: : Cleanup and verification of SVD output
clusterdump: : Dump cluster output to text
dirichlet: : Dirichlet Clustering
eigencuts: : Eigencuts spectral clustering
evaluateFactorization: : compute RMSE of a rating matrix factorization against probes in memory
evaluateFactorizationParallel: : compute RMSE of a rating matrix factorization against probes
fkmeans: : Fuzzy K-means clustering
fpg: : Frequent Pattern Growth
itemsimilarity: : Compute the item-item-similarities for item-based collaborative filtering
kmeans: : K-means clustering
lda: : Latent Dirchlet Allocation
ldatopics: : LDA Print Topics
lucene.vector: : Generate Vectors from a Lucene index
matrixmult: : Take the product of two matrices
meanshift: : Mean Shift clustering
parallelALS: : ALS-WR factorization of a rating matrix
predictFromFactorization: : predict preferences from a factorization of a rating matrix
prepare20newsgroups: : Reformat 20 newsgroups data
recommenditembased: : Compute recommendations using item-based collaborative filtering
rowid: : Map SequenceFile to {SequenceFile, SequenceFile}
rowsimilarity: : Compute the pairwise similarities of the rows of a matrix
runlogistic: : Run a logistic regression model against CSV data
seq2sparse: : Sparse Vector generation from Text sequence files
seqdirectory: : Generate sequence files (of Text) from a directory
seqdumper: : Generic Sequence File dumper
seqwiki: : Wikipedia xml dump to sequence file
spectralkmeans: : Spectral k-means clustering
splitDataset: : split a rating dataset into training and probe parts
ssvd: : Stochastic SVD
svd: : Lanczos Singular Value Decomposition
testclassifier: : Test Bayes Classifier
trainclassifier: : Train Bayes Classifier
trainlogistic: : Train a logistic regression using stochastic gradient descent
transpose: : Take the transpose of a matrix
vectordump: : Dump vectors from a sequence file to text
wikipediaDataSetCreator: : Splits data set of wikipedia wrt feature like country
wikipediaXMLSplitter: : Reads wikipedia data and creates ch
输入命令:hdp
预期结果:
Usage: hadoop [–config confdir] COMMAND
where COMMAND is one of:
namenode -format format the DFS filesystem
secondarynamenode run the DFS secondary namenode
namenode run the DFS namenode
datanode run a DFS datanode
dfsadmin run a DFS admin client
mradmin run a Map-Reduce admin client
fsck run a DFS filesystem checking utility
fs run a generic filesystem user client
balancer run a cluster balancing utility
fetchdt fetch a delegation token from the NameNode
jobtracker run the MapReduce job Tracker node
pipes run a Pipes job
tasktracker run a MapReduce task Tracker node
historyserver run job history servers as a standalone daemon
job manipulate MapReduce jobs
queue get information regarding JobQueues
version print the version
jar run a jar file
distcp copy file or directories recursively
archive -archiveName NAME -p * create a hadoop archive
classpath prints the class path needed to get the
Hadoop jar and the required libraries
daemonlog get/set the log level for each daemon
or
CLASSNAME run the class named CLASSNAME
Most commands print help when invoked w/o parameters.
五、运行
步骤一:
通过这个命令可以查看mahout提供了哪些算法,以及如何使用
mahout –help
mahout kmeans –input /user/hive/warehouse/tmp_data/complex.seq –clusters 5 –output /home/hadoopuser/1.txt
mahout下处理的文件必须是SequenceFile格式的,所以需要把txtfile转换成sequenceFile。SequenceFile是hadoop中的一个类,允许我们向文件中写入二进制的键值对,具体介绍请看
eyjian写的http://www.hadoopor.com/viewthread.php?tid=144&highlight=sequencefile
mahout中提供了一种将指定文件下的文件转换成sequenceFile的方式。
(You may find Tika (http://lucene.apache.org/tika) helpful in converting binary documents to text.)
使用方法如下:
$MAHOUT_HOME/mahout seqdirectory \
--input –output \
{UTF-8|cp1252|ascii…}> \
64> \
>
举个例子:
mahout seqdirectory –input /hive/hadoopuser/ –output /mahout/seq/ –charset UTF-8
步骤二:
运行kmeans的简单的例子:
1:将样本数据集放到hdfs中指定文件下,应该在testdata文件夹下
$HADOOP_HOME/hdp fs -put testdata
例如:
dap fs -put ~/datasetsynthetic_controltest/synthetic_control.data ~/local/mahout/testdata/
2:使用kmeans算法
hdp jar $MAHOUT_HOME/examples/target/mahout-examples-$MAHOUT_VERSION.job org.apache.mahout.clustering.syntheticcontrol.kmeans.Job
例如:
hdp jar /home/hadoopuser/mahout-0.3/mahout-examples-0.1.job org.apache.mahout.clustering.syntheticcontrol.kmeans.Job
3:使用canopy算法
hdp jar $MAHOUT_HOME/examples/target/mahout-examples-$MAHOUT_VERSION.job org.apache.mahout.clustering.syntheticcontrol.canopy.Job
例如:
hdp jar /home/hadoopuser/mahout-0.3/mahout-examples-0.1.job org.apache.mahout.clustering.syntheticcontrol.canopy.Job
4:使用dirichlet 算法
mahout jar $MAHOUT_HOME/examples/target/mahout-examples-$MAHOUT_VERSION.job org.apache.mahout.clustering.syntheticcontrol.dirichlet.Job
5:使用meanshift算法
meanshift :
hdp jar $MAHOUT_HOME/examples/target/mahout-examples-$MAHOUT_VERSION.job org.apache.mahout.clustering.syntheticcontrol.meanshift.Job
6:查看一下结果吧
mahout vectordump –seqFile /user/hadoopuser/output/data/part-00000
这个直接把结果显示在控制台上。
可以到hdfs中去看看数据是什么样子的
上面跑的例子大多以testdata作为输入和输出文件夹名
可以使用 hdp fs -lsr 来查看所有的输出结果
KMeans 方法的输出结果在 output/points
Canopy 和 MeanShift 结果放在了 output/clustered-points
https://www.cnblogs.com/end/category/284624.html
java 调用 mahout_(转)Mahout使用入门相关推荐
- java 调用 mahout_使用 Mahout 实现内容分类
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 Mahout 目前支持两种根据贝氏统计来实现内容分类的方法.第一种方法是使用简单的支持 Map-Reduce 的 Naive Bayes 分类器.Naiv ...
- java 调用 mahout_java – 运行Mahout本地获取MahoutDriver的ClassNotFoundException
我试图在 Windows 8机器上本地运行Mahout(没有Hadoop).我意识到这不是最佳设置,但这就是我必须使用的. 当我尝试运行bin / mahout时,我收到以下错误: $bin/maho ...
- java调用jasper_Java开源报表Jasper入门(2) -- 使用JasperSoft Studio创建一个简单报表
在接下来的教程中,我们将实现一个简单的JasperReports示例,展现其基本的开发.使用流程.文章很长,不过是以图片居多,文字并不多. 实例中使用最新的Jasper Studio5.2进行报表设计 ...
- Swig超详细入门教程(Java调用C/C++, CMake)——更新于2021.12
目录 相关教程 环境配置 0基础上手例子(C/C++) 使用CMake的例子(C语言) 使用CMake的例子(C++) 本文主要是手把手教萌新们如何用官方用例构建(有许多本人亲身踩坑血泪史) 相关教程 ...
- Java基础-SSM之mybatis快速入门篇
Java基础-SSM之mybatis快速入门篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 其实你可能会问什么是SSM,简单的说就是spring mvc + Spring + m ...
- 基于 Android NDK 的学习之旅-----Java 调用C(附源码)
基于 Android NDK 的学习之旅-----Java 调用C 随便谈谈为什么要Java调用C 吧: 我认为: 1. 有些公司开发Android项目的时候, 许多组件功能可能是C中已经实现了,所 ...
- 学习笔记:Java 并发编程①_基础知识入门
若文章内容或图片失效,请留言反馈. 部分素材来自网络,若不小心影响到您的利益,请联系博主删除. 视频链接:https://www.bilibili.com/video/av81461839 视频下载: ...
- Java调用c/c++(JNI)最详细步骤
一.JNI(Java Native Interface)的作用就是Java通过JNI调用其他语言的函数(或方法)(主要是C&C++). 二.准备 1. java8系列jdk,有很多版本,任选一 ...
- IDL学习记录和Java调用IDL方法
IDL学习记录和Java调用IDL方法 2018年02月06日 08:32:02 回首1949 阅读数:385更多 个人分类: 随想 版权声明:乐呵乐呵得了 https://blog.csdn.net ...
最新文章
- 中国民航大学计算机学院宿舍,中国民航大学计算机科学与技术学院研究生导师简介-谢丽霞_清华大学宿舍...
- python零基础实例-Python初学零基础也不怕,从0开始!
- SDUT—2054数据结构实验之链表九:双向链表 (基本建立)
- bidirectional pathtracing算法学习
- 在vue单页应用中使用jquery
- php远程文件包含攻击,PHP “is_a()”函数远程文件包含漏洞
- xshell vim 不能粘贴_linux基础知识:vim(vi)的知识
- 学习web前端要了解的HTML5知识有哪些?
- 奇讯新游 PHP,QXPLAY
- akb48_原AKB48成员板野友美结婚了!闪嫁23岁职棒球员高桥奎二
- 关于某学习通网页鼠标不能移出视频窗口的问题
- 数学建模竞赛大汇总,别再被野鸡竞赛坑啦
- shark-0.9.1 安装后测试
- WHENet: Real-time Fine-Grained Estimation for Wide Range Head Pose
- 前端实现内网在线excel编辑和word在线编辑相关建议
- Android UI最佳实践
- 计算机win7卡顿如何解决方法,win7电脑玩2D游戏经常发生卡顿六大解决方法
- linaro公司:交叉编译器 arm-linux-gnueabi 和 arm-linux-gnueabihf 的区别
- 关于DIN 5510-2德国轨道车辆防火测试标准
- 轻松一键ROOT教程,root工具