LoginSignup
10
11

More than 5 years have passed since last update.

Mahoutでレコメンドを動かすまで(その1)

Last updated at Posted at 2014-09-20

はじめに

MahoutをWindowsで動かしAmazonのレコメンドみたいなものをやってみようといろいろ試しましたが、いろいろなエラーに遭遇したため一旦あきらめ、まずはLinuxを使うことにしました。Windowsの方はまた動かせるようになったら報告します。

Linux版の方でも動かすためにはいろいろ躓くポイントがありました。以下、とりあえず動かすまでにやったことを記します。環境は以下を使用しました。まずはお試しということでHadoopは無しでやっています。

  • Ubuntu 10.0.4
  • Mahout 0.9

JAVA_HOMEが必要

Mahoutをダウンロード、展開していきなりコマンドをたたくと、以下のように怒られます。環境変数JAVA_HOMEにJavaのインストール先を設定する必要があるようです。

vmplanet@ubuntu:~/mahout-distribution-0.9$ bin/mahout
Error: JAVA_HOME is not set.

MAHOUT_JAVA_HOMEがあるときはJAVA_HOMEのかわりにこちらが使われるとのことなので、この変数にJavaのインストール先を設定します。

export MAHOUT_JAVA_HOME=/usr/lib/jvm/java-6-openjdk

ちなみに環境変数の一覧はbin/mahoutの中を除くと説明が書いてあります。

ヒープが足りない

使っていたLinux環境のメモリが少なかったのが原因ですがMAHOUT_JAVA_HOMEを設定して動かすと今度は以下のエラーになりました。

vmplanet@ubuntu:~/mahout-distribution-0.9$ bin/mahout 
hadoop binary is not in PATH,HADOOP_HOME/bin,HADOOP_PREFIX/bin, running locally
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

ヒープを確保できなかったというエラー。確保するヒープサイズはMAHOUT_HEAPSIZEに設定するようです。単位はMBです。指定しない場合のデフォルトは1024らしいので、これだけ確保しようとして失敗していたのが原因のようです。

とりあえず以下のように少し少なめに設定しました。

export MAHOUT_HEAPSIZE=512

ここまで設定してやっと動くようになりました。
引数を何もつけないで実行すると使える分析アルゴリズムの一覧が表示されます。

vmplanet@ubuntu:~/mahout-distribution-0.9$ bin/mahout
hadoop binary is not in PATH,HADOOP_HOME/bin,HADOOP_PREFIX/bin, running locally
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<Text,VectorWritable> to {SequenceFile<IntWritable,VectorWritable>, SequenceFile<IntWritable,Text>}
  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

お勧め商品などのレコメンドを計算するにはrecommenditembasedというアルゴリズムを使います。早速これを使ったレコメンドをしてみたいと思いますが長くなったのでその2に続く...

→その2はこちら

10
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
11