在此先感謝...我需要使用apache spark創建一個期限文檔矩陣......任何人都可以告訴我如何使用java的mllib庫spark.Also可以使用mllib實現關聯傳播算法。使用apache spark mllib庫的期限文檔矩陣
1
A
回答
1
於火花文檔分類看看樸素貝葉斯 http://spark.apache.org/docs/latest/mllib-naive-bayes.html
您可能還需要看看在TF-IDF方法 http://spark.apache.org/docs/latest/mllib-feature-extraction.html
1
看一看下面blog的細節。這裏有一個總結:
sc = SparkContext('local', 'term_doc')
corpus = sc.parallelize([
"It is the east, and Juliet is the sun.",
"A dish fit for the gods.",
"Brevity is the soul of wit."])
tokens = corpus.map(lambda raw_text: raw_text.split()).cache()
local_vocab_map = tokens.flatMap(lambda token: token).distinct()\
.zipWithIndex().collectAsMap()
vocab_map = sc.broadcast(local_vocab_map)
vocab_size = sc.broadcast(len(local_vocab_map))
term_document_matrix = tokens \
.map(Counter) \
.map(lambda counts: {vocab_map.value[token]: float(counts[token]) for token in counts})\
.map(lambda index_counts: SparseVector(vocab_size.value, index_counts))
for doc in term_document_matrix.collect():
print doc`
這將產生以下輸出:
>>> tokens.first()
['It', 'is', 'the', 'east,', 'and', 'Juliet', 'is', 'the', 'sun.']
>>> local_vocab_map
{'and': 0, 'A': 1, 'fit': 14, 'for': 13, 'of': 3, 'is': 4, 'gods.': 7, 'It': 11,\
'Brevity': 10, 'soul': 12, 'sun.': 8, 'dish': 2, 'east,': 9, 'the': 5, 'wit.': 6, 'Juliet': 15}
>>> for doc in term_document_matrix.collect():
print doc
(16,[0,4,5,8,9,11,15],[1.0,2.0,2.0,1.0,1.0,1.0,1.0])
(16,[1,2,5,7,13,14],[1.0,1.0,1.0,1.0,1.0,1.0])
(16,[3,4,5,6,10,12],[1.0,1.0,1.0,1.0,1.0,1.0])
相關問題
- 1. 有效期限文檔矩陣與NLTK
- 2. 調整Apache Spark MLlib算法
- 3. [R文本挖掘轉換期限文檔矩陣
- 4. 使用mllib時的矩陣乘法錯誤
- 5. 從Spark上使用Breeze MLlib
- 6. Apache Spark MLlib LabeledPoint空標籤問題
- 7. Apache Spark MLlib - 從數據獲取LabeledPoint(Java)
- 8. Spark 1.4 Mllib LDA topicDistributions()返回錯誤的文檔數
- 9. Spark Apache源代碼
- 10. Spark MLLIB問題
- 11. 如何將MLlib Apache Spark庫安裝到JAVA Eclpise項目中?
- 12. Java中Spark MLlib的分類
- 13. 當DataFrame有列時如何使用Java Apache Spark MLlib?
- 14. Spark mllib ALS建議
- 15. 結合Spark Streaming + MLlib
- 16. 使用Apache Spark/Spark SQL加入文件
- 17. Spark mllib使用scala進行分類
- 18. f1score的Spark mllib閾值
- 19. apache spark MLLib:如何構建字符串特徵的標記點?
- 20. 使用MLib的Apache Spark中的分類變量
- 21. 矩陣庫更新
- 22. 如何理解OpenGL文檔的矩陣?
- 23. Spark mllib洗牌數據
- 24. Apache Spark與Scala - 從矩陣中添加行
- 25. 文本分析:術語文檔矩陣?
- 26. Spark MLlib/K-Means直覺
- 27. 在apache spark 2.0.2中使用mllib和「無法解析導入org.apache.spark.mllib」錯誤
- 28. Spark MLlib IDF洗牌數據?
- 29. 如何將字符串從csv轉換爲Apache Spark MLlib
- 30. 將Apache Spark mllib模型保存在python中