mahout的安装及kmeans算法案例的测试

【前言】
Mahout 是一个很强大的数据挖掘工具,是一个分布式机器学习算法的集合,包括:被称为Taste的分布式协同过滤的实现、分类、聚类等。Mahout最大的优点就是基于hadoop实现,把很多以前运行于单机上的算法,转化为了MapReduce模式,这样大大提升了算法可处理的数据量和处理性能。

最主要的是mahout提供了很多机器学习的算法

mahout的安装及kmeans算法案例的测试_第1张图片
Paste_Image.png

【安装部署】

注意:mahout的运行方式有两种,一种是local本地运行,一种是结合hadoop运行,这里主要记录mahout在hadoop上运行

#下载源码
    http://archive.apache.org/dist/mahout/

#解压
    tar -xzvf mahout-distribution-0.9.tar.gz

#配置内容
    --java配置
    export JAVA_HOME="/opt/jdk1.7.0_79"

    --hadoop配置(这里是hadoop1.x的配置)
    export HADOOP_HOME_WARN_SUPPRESS="1"
    export HADOOP_HOME=/usr/local/hadoop 
    export HADOOP_CONF_DIR=$HADOOP_HOME/conf
    
    
    export MAHOUT_HOME="/usr/local/mahout-0.9" 
    export MAHOUT_CONF_DIR="$MAHOUT_HOME/conf"
    export MAHOUT_LOCAL=""
    export PATH=".:$HADOOP_HOME/bin:$MAHOUT_HOME/conf:$MAHOUT_HOME/bin:$JAVA_HOME/bin:$PATH"

    
    export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$MAHOUT_HOME/lib:$HADOOP_CONF_DIR/:$JAVA_HOME/lib/tools.jar


#启动hadoop
    ./start-all.sh

#验证mahout
    mahout


#启动日志
[root@hadoop Desktop]# mahout
MAHOUT_LOCAL is not set; adding HADOOP_CONF_DIR to classpath.
Running on hadoop, using /usr/local/hadoop/bin/hadoop and HADOOP_CONF_DIR=/usr/local/hadoop/conf
MAHOUT-JOB: /usr/local/mahout-0.9/mahout-examples-0.9-job.jar
An example program must be given as the first argument.
Valid program names are:
  arff.vector: : Generate Vectors from an ARFF file or directory
  baumwelch: : Baum-Welch algorithm for unsupervised HMM training
  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
  clusterpp: : Groups Clustering Output In Clusters
  cmdump: : Dump confusion matrix in HTML or text formats
  concatmatrices: : Concatenates 2 matrices of same cardinality into a single matrix
  cvb: : LDA via Collapsed Variation Bayes (0th deriv. approx)
  cvb0_local: : LDA via Collapsed Variation Bayes, in memory locally.
  evaluateFactorization: : compute RMSE and MAE of a rating matrix factorization against probes
  fkmeans: : Fuzzy K-means clustering
  hmmpredict: : Generate random sequence of observations by given HMM
  itemsimilarity: : Compute the item-item-similarities for item-based collaborative filtering
  kmeans: : K-means clustering
  lucene.vector: : Generate Vectors from a Lucene index
  lucene2seq: : Generate Text SequenceFiles from a Lucene index
  matrixdump: : Dump matrix in CSV format
  matrixmult: : Take the product of two matrices
  parallelALS: : ALS-WR factorization of a rating matrix
  qualcluster: : Runs clustering experiments and summarizes results in a CSV
  recommendfactorized: : Compute recommendations using the factorization of a rating matrix
  recommenditembased: : Compute recommendations using item-based collaborative filtering
  regexconverter: : Convert text files on a per line basis based on regular expressions
  resplit: : Splits a set of SequenceFiles into a number of equal splits
  rowid: : Map SequenceFile to {SequenceFile, SequenceFile}
  rowsimilarity: : Compute the pairwise similarities of the rows of a matrix
  runAdaptiveLogistic: : Score new production data using a probably trained and validated AdaptivelogisticRegression model
  runlogistic: : Run a logistic regression model against CSV data
  seq2encoded: : Encoded Sparse Vector generation from Text sequence files
  seq2sparse: : Sparse Vector generation from Text sequence files
  seqdirectory: : Generate sequence files (of Text) from a directory
  seqdumper: : Generic Sequence File dumper
  seqmailarchives: : Creates SequenceFile from a directory containing gzipped mail archives
  seqwiki: : Wikipedia xml dump to sequence file
  spectralkmeans: : Spectral k-means clustering
  split: : Split Input data into test and train sets
  splitDataset: : split a rating dataset into training and probe parts
  ssvd: : Stochastic SVD
  streamingkmeans: : Streaming k-means clustering
  svd: : Lanczos Singular Value Decomposition
  testnb: : Test the Vector-based Bayes classifier
  trainAdaptiveLogistic: : Train an AdaptivelogisticRegression model
  trainlogistic: : Train a logistic regression using stochastic gradient descent
  trainnb: : Train the Vector-based Bayes classifier
  transpose: : Take the transpose of a matrix
  validateAdaptiveLogistic: : Validate an AdaptivelogisticRegression model against hold-out data set
  vecdist: : Compute the distances between a set of Vectors (or Cluster or Canopy, they must fit in memory) and a list of Vectors
  vectordump: : Dump vectors from a sequence file to text
  viterbi: : Viterbi decoding of hidden states from given output states sequence
[root@hadoop Desktop]# 

以上表名启动成功

【运行kmeans算法案例】

#测试数据准备
    下载地址:http://archive.ics.uci.edu/ml/databases/synthetic_control/synthetic_control.data

#hdfs上创建测试目录(目录名必须是testdata)
     hadoop fs -mkdir ./testdata  或者 hadoop  fs -mkdir /user/root/testdata(即本用户目录下,这里是root用户)

#上传测试数据
    hadoop fs -put /mahoutTestData.txt ./  或者  hadoop fs -put /mahoutTestData.txt /user/root/testdata

#运行
    hadoop jar mahout-examples-0.9-job.jar org.apache.mahout.clustering.syntheticcontrol.kmeans.Job
#查看结果
    hadoop fs -ls ./output

#我们会发现结果是乱码的(mahout转码打开)
    mahout vectordump -i ./output/data/part-m-00000
mahout的安装及kmeans算法案例的测试_第2张图片
上传后的测试数据源.png

![运行完成.png . . .]
](http://upload-images.jianshu.io/upload_images/2608446-12a1737d2093633e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

mahout的安装及kmeans算法案例的测试_第3张图片
结果列表.png
mahout的安装及kmeans算法案例的测试_第4张图片
计算后的结果源.png

你可能感兴趣的:(mahout的安装及kmeans算法案例的测试)