使用LDA中的主题建模信息作为功能,通过SVM执行文本分类

ast*_*rix 6 python classification svm lda

我想使用主题建模信息作为提供给svm分类器的功能来执行文本分类.所以我想知道如何通过在数据集的训练和测试分区上执行LDA来生成主题建模功能,因为corprus会更改数据集的两个分区?

我做错了假设吗?

你能用scikit学习提供一个如何做到这一点的例子吗?

Ash*_*Ash 5

你的假设是对的.您所做的是根据训练数据训练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特征连接起来.

  • 我会对人们使用SVM等LDA功能的经验感兴趣.我做了一些尝试,发现它们对于手头的问题或多或少都没用 - 性能没有改善单词/ n-gram功能(我使用如果我记得的话,单词和2克).没有word/n-gram功能,性能非常糟糕. (2认同)