本文整理汇总了Python中sklearn.decomposition.LatentDirichletAllocation.components_方法的典型用法代码示例。如果您正苦于以下问题:Python LatentDirichletAllocation.components_方法的具体用法?Python LatentDirichletAllocation.components_怎么用?Python LatentDirichletAllocation.components_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.decomposition.LatentDirichletAllocation
的用法示例。
在下文中一共展示了LatentDirichletAllocation.components_方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LatentDirichletAllocation
# 需要导入模块: from sklearn.decomposition import LatentDirichletAllocation [as 别名]
# 或者: from sklearn.decomposition.LatentDirichletAllocation import components_ [as 别名]
# Index documents with unique IDs
corpusIndexed = corpusMapped.zipWithIndex().map(lambda x: [x[1], x[0]]).cache()
nTopics = 10
ldaModel = LDA.train(corpusIndexed, k=nTopics)
# Dirty trick -- use sklearn LDA to do the transform step
# This should be possible on Spark, but can't figure out how
from sklearn.decomposition import LatentDirichletAllocation
lda = LatentDirichletAllocation(n_topics=nTopics, max_iter=1,
learning_method='online', learning_offset=50.
)
doc0 = corpusIndexed.first()[1].toArray()
lda.fit(doc0)
lda.components_ = ldaModel.topicsMatrix().T
def getDocumentTopics(docTokens, lda):
wcTuples = dic.doc2bow(docTokens)
data = []
row = []
col = []
for w, c in wcTuples:
col.append(0)
row.append(w)
data.append(c)
nSamples = 1
nFeatures = len(dic)