首先,下载数据集20news-bydate.tar.gz,在$MAHOUT_HOME下的 examples/bin/下建立work文件夹(mkdir /home/hadoop/mahout-distribution-0.4 /examples/bin/work/)将下载的数据集解压tar 20news-bydate.tar.gz,之后放到work文件夹下。
其次,产生Input数据集,即对训练数据集进行预处理,数据准备阶段,将各类中的数据进行分词处理,去掉标点及副词等,同时将各类中的文件读入到一个大文件中,使得每类最后只有一个文件包含起初所有的文件,mahout下处理的文件必须是SequenceFile格式的,还需要把txtfile转换成 sequenceFile。等处理完看结果时就明白了,
命令为:mahout org.apache.mahout.classifier.bayes.PrepareTwentyNewsgroups -p /home/hadoop/mahout-distribution-0.4/examples/bin/work/20news-bydate-train -o /home/hadoop/mahout-distribution-0.4/examples/bin/work/bayes-train-input -a org.apache.mahout.vectorizer.DefaultAnalyzer -c UTF-8
完毕后将work 下的bayes-train-input放到hadoop的分布式文件系统上的 20news-input,输入命令 hadoop dfs -put /home/hadoop/mahout-distribution-0.4/examples/bin/work/bayes-train-input 20news-input
第三,用处理好的训练数据集进行训练得出分类模型即中间结果,模型保存在分布式文件系统上,在mahout的目录下输入命令 mahout trainclassifier -i 20news-input -o newsmodel -type bayes -ng 3 -source hdfs
或者输入命令:hadoop jar $MAHOUT_HOME/mahout-examples-0.5-job.jar org.apache.mahout.classifier.bayes.TrainClassifier -i 20news-input -o newsmodel -type bayes -ng 3 -source hdfs
当然可以查看newsmodel里的内容时,先查看其里面都有什么,命令:hadoop fs -lsr /user/hadoop/newsmodel
将其导入到本地txt格式,进行查看,例如命令:mahout seqdumper -s /user/hadoop/newsmodel/trainer-tfIdf//trainer-tfIdf/part-00000 -o /home/hadoop/out/part-1
最后,用模型进行测试,输入命令:mahout testclassifier -m newsmodel -d 20news-input -type bayes -ng 3 -source hdfs -method mapreduce
转自:http://hi.baidu.com/bjwyl66/blog/item/32f0820d25ecfbf2ab6457f3.html
分享到:
相关推荐
【甘道夫】通过Mahout构建贝叶斯文本分类器案例详解 -- 配套源码
mahout,朴素贝叶斯分类,中文分词,mahout,朴素贝叶斯分类,中文分词,
Mahout 贝叶斯算法根据模型分类无标签数据,具体参考http://blog.csdn.net/fansy1990/article/details/37991447
mahout-examples-0.11.1 mahout-examples-0.11.1-job mahout-h2o_2.10-0.11.1 mahout-h2o_2.10-0.11.1-dependency-reduced mahout-hdfs-0.11.1 mahout-integration-0.11.1 mahout-math-0.11.1 mahout-math-0.11.1 ...
mahout_help,mahout的java api帮助文档,可以帮你更轻松掌握mahout
maven_mahout_template-mahout-0.8
使用mahout机器学习改进solr查询结果
Mahout 官方文档,简单介绍Mahout概念及其安装和简单使用
mahoutAlgorithms源码分析 mahout代码解析
MAHOUT实战 MAHOUT IN ACTION
mahout-integration-0.7mahout-integration-0.7mahout-integration-0.7mahout-integration-0.7
Mahout0.8_API 喜欢的人就请下载吧
Apache Mahout 简介
mahout0.9不能运行在hadoop2中,会报interface错误,用此新编译后的包,可实现mahout+hadoop2的运行环境,其中包括编译后的包及源码。
spring-mahout-demo-----一个简单的spring-mahout结合的例子,是很好的学习开发思路的例子。
Mahout支持K-Means等聚类算法,在此zip包中已经有打好jar包的资源,不需要用户再打jar包,可以直接使用。
自己制作的mahout的API,方便使用时的查询。全英文的。
mahout-core-0.9.jar+mahout-core-0.8.jar+mahout-core-0.1.jar
mahout 入门中文材料,是IBM文章汇总,值得一看