机器学习 -LDA模型

1. 模型相关参数

  1. n_components: 主题的数量。越大,topic越多,perplexity越小,也越容易过拟合。可以画出n_components vs perplexity的变化曲线来确定;
    1. doc_topic_prior,文本-主题的先验分布theta,默认为 1 n _ c o m p o n e n t s \frac{1}{n\_components} n_components1
    1. topic_word_prior: 主题-单词先验分布beta,默认为 1 n _ c o m p o n e n t s \frac{1}{n\_components} n_components1
  2. learning_method:更新主题-单词分布的的学习方式
    1. batch: Batch variational Bayes–批量变分贝叶斯方法,利用所有的数据做EM更新。
    2. online:当数据量比较大时,采用min_batch来更新主题词分布。mini_batch学习率受到learning_decay和learning_offset的影响;
  3. learning_decay: 在online学习过程中,用来控制learning_rate的衰减情况,learning_decay设置在[0.5, 1]之间来保证共轭分布的收敛性。
  4. learning_offset: 在online 学习过程中,前面训练样本批次对最终模型的影响。
  5. max_iter: 最大迭代次数;
  6. batch_size:在online学习过程中,使用多少batch_size的样本进行EM迭代;
  7. evalueate_every: 进行perplexity评估的频率,perplexity 可以比较方便地评估模型训练的收敛情况。
  8. perp_tol: perplexity的tolerance。

2. 相关代码

lda = LatentDirichletAllocation(n_components=200, max_iter=10,
                                learning_method='online',)
lda.fit(tfidf)
# 主题词分布
feature_names = tfidf_vectorizer.get_feature_names()
topic_term = lda.components_
for j, topic in enumerate(topic_term):
    top_str = ''
    for i in range(len(feature_names)):
        top_str += '{}%*{} + '.format(round(topic[i] * 100, 3), feature_names[i])
    if j != 0 and j % 150 == 0:
        print(top_str)     

在这里插入图片描述

3. 收敛效果(perplexity)

通过调用lda.perplexity(X)函数,可以得知当前训练的perplexity,sklearn中对perplexity的定义为exp(-1. * log-likelihood per word

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值