【发布时间】:2018-07-26 05:09:37
【问题描述】:
下面我创建了一个完整的可重现示例来计算给定 DataFrame 的主题模型。
import numpy as np
import pandas as pd
data = pd.DataFrame({'Body': ['Here goes one example sentence that is generic',
'My car drives really fast and I have no brakes',
'Your car is slow and needs no brakes',
'Your and my vehicle are both not as fast as the airplane']})
from sklearn.decomposition import LatentDirichletAllocation
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer(lowercase = True, analyzer = 'word')
data_vectorized = vectorizer.fit_transform(data.Body)
lda_model = LatentDirichletAllocation(n_components=4,
learning_method='online',
random_state=0,
verbose=1)
lda_topic_matrix = lda_model.fit_transform(data_vectorized)
问题:如何按主题过滤文档?如果是这样,文档可以有多个主题标签,还是需要一个阈值?
最后,我喜欢将每个文档标记为“1”,这取决于它是否具有主题 2 和主题 3 的高负载,否则为“0”。
【问题讨论】:
标签: python scikit-learn lda topic-modeling