基于自然语言处理的交易策略研究
1. LDA无监督学习示例
LDA(Latent Dirichlet Allocation)在主题建模中应用广泛,因其能生成人类可解读的有意义主题,为新文档分配主题,且具有可扩展性。其工作原理基于一个关键假设:文档生成时先选择主题,再为每个主题选择一组词汇,算法通过逆向工程找出文档中的主题。
以下是一个使用LDA进行主题建模的代码示例:
sentences = [
'The stock price of google jumps on the earning data today',
'Google plunge on China Data!'
]
# 获取词袋
from sklearn.decomposition import LatentDirichletAllocation
from sklearn.feature_extraction.text import CountVectorizer
vect = CountVectorizer(ngram_range=(1, 1), stop_words='english')
sentences_vec = vect.fit_transform(sentences)
# 在词袋上运行LDA
lda = LatentDirichletAllocation(n_components=3)
lda.fit_transform(sentences_vec)
输出结果如下:
array([[0.0428324
超级会员免费看
订阅专栏 解锁全文
898

被折叠的 条评论
为什么被折叠?



