2014-01-22 50 views

回答

6

關於mahout中LDA最新形式的文檔是有點稀疏。現在叫做'cvb'。輸入可以是文本文件的目錄或其他任何內容(lucene索引,無論),你可以進入mahout形式。輸出是以向量形式的關鍵字表示的定義數量的主題(請參見下面的示例)。

我昨天實際上已經通過一個例子,所以我將在下面粘貼一些命令以便有用。該示例使用可使用命令在http://svn.apache.org/repos/asf/mahout/tags/mahout-0.4/examples/bin/build-reuters.sh

發現(可能是過時的)被加載路透社的數據集(例如:輸入會去$ BASEDIR /工作/路透輸出/下)

#設置一些目錄

basedir=[set to your current directory] 
workdir=$basedir/work 

#轉換文本格式SequenceFile

mahout seqdirectory \ 
-i $basedir/work/reuters-out/ \ 
-o $basedir/work/reuters-out-seqdir -c UTF-8 -chunk 5 

#使稀疏矢量

mahout seq2sparse \ 
    -i $workdir/reuters-out-seqdir/ \ 
    -o $workdir/reuters-out-seqdir-sparse-lda -ow --maxDFPercent 85 --namedVector 

#使用rowid將稀疏向量轉換爲cvb集羣所需的格式(即將Text鍵更改爲Integer)。

mahout rowid \ 
-i $workdir/reuters-out-seqdir-sparse-lda/tfidf-vectors \ 
-o $workdir/reuters-out-matrix 

#重新運行LDA使用本地命令

#以下:Run cvb in mahout 0.8

rm -rf $workdir/reuters-ldalocal $workdir/reuters-ldalocal-topics 
mahout cvb0_local \ 
    -i $workdir/reuters-out-matrix/matrix \ 
    -d $workdir/reuters-out-seqdir-sparse-lda/dictionary.file-* \ 
    -a 0.5 \ 
    -top 4 \ 
    -do $workdir/reuters-ldalocal \ 
    -to $workdir/reuters-ldalocal-topics 

#檢查通過顯示每個主題的頂部10個字的輸出:

mahout vectordump \ 
    -i $workdir/reuters-ldalocal-topics \ 
    --dictionary $workdir/reuters-out-seqdir-sparse-lda/dictionary.file-* \ 
    --dictionaryType sequencefile \ 
    --vectorSize 10 \ 
    -sort $workdir/reuters-ldalocal-topics 

的輸出看起來像這樣:

{said:12099.546951505947,its:10566.985916212521,year:8333.832279174481,dlrs:6810.206141819796,would:6721.746234281428,been:5329.6753421933945,pct:5313.369659313288,billion:5248.896294419074,from:5158.844069513761,he:4764.16474083869} 
{mln:11816.704457054004,cts:7169.159831834528,mar:7081.733955520149,vs:6891.4237560938955,new:6560.720833985039,has:6543.337854529879,1986:6043.850306111383,company:5720.025984843189,pct:5711.399291651732,last:5683.42288907518} 
{inc:9704.372248376018,mln:9278.314888220315,said:8562.15377124544,net:7827.149394593728,vs:7736.055883103908,dlrs:7057.160090724306,cts:6177.1590584797605,market:5936.459595191674,exchange:5371.911394611647,co:5314.4250562522} 
{said:12514.11646492775,u.s:9207.239974183465,from:7679.363044582878,mar:6588.0987950965,bank:6491.528794438723,pct:6100.417335098452,has:5352.990453581582,dlrs:5091.309618540722,about:4886.923813272583,13:4695.692587191373} 

免責聲明 - 這是我的筆記釋義,可能有小錯誤。祝你好運!

+0

非常感謝Ziggy。欣賞很多 –

相關問題