ast*_*rix 6 python classification svm lda
我想使用主题建模信息作为提供给svm分类器的功能来执行文本分类.所以我想知道如何通过在数据集的训练和测试分区上执行LDA来生成主题建模功能,因为corprus会更改数据集的两个分区?
我做错了假设吗?
你能用scikit学习提供一个如何做到这一点的例子吗?
你的假设是对的.您所做的是根据训练数据训练LDA,然后根据训练模型转换训练和测试数据.
所以你会有这样的事情:
from sklearn.decomposition import LatentDirichletAllocation as LDA
lda = LDA(n_topics=10,...)
lda.fit(training_data)
training_features = lda.transform(training_data)
testing_features = lda.transform(testing_data)
Run Code Online (Sandbox Code Playgroud)
如果我是你,如果你的弓特征稀疏,我会使用numpy.hstack或scipy.hstack将LDA特征与Bag of words特征连接起来.