参考链接: https://www.codenong.com/60246570/

报错原因:D:\software\Anaconda\envs\LDA\lib\site-packages\gensim\topic_coherence\direct_confirmation_measure.py:204: RuntimeWarning: divide by zero encountered in double_scalars
m_lr_i = np.log(numerator / denominator)
D:\software\Anaconda\envs\LDA\lib\site-packages\gensim\topic_coherence\indirect_confirmation_measure.py:323: RuntimeWarning: invalid value encountered in double_scalars
return cv1.T.dot(cv2)[0, 0] / (_magnitude(cv1) * _magnitude(cv2))
nan

数据准备

     dataAll, data = data_dispose.loaddata()# print(dataAll.content_cutted)train = []for line in dataAll.content_cutted:line = [word.strip() for word in line.split(' ')]train.append(line)print(type(train))# exit()dictionary = corpora.Dictionary(train)corpus = [dictionary.doc2bow(test) for test in train]

修改前

    def coherence(num_topics):lda = models.LdaModel(corpus=corpus, id2word=dictionary, num_topics=num_topics, passes=60, alpha=5, eta=0.01,random_state=1)print(lda.print_topics(num_topics=num_topics, num_words=10))ldacm = models.CoherenceModel(model=lda, texts=corpus, dictionary=dictionary, coherence='c_v')print(ldacm.get_coherence())return ldacm.get_coherence()

修改完(将CoherenceModel函数中的texts参数值从corpus修改为train)

    def coherence(num_topics):lda = models.LdaModel(corpus=corpus, id2word=dictionary, num_topics=num_topics, passes=60, alpha=5, eta=0.01,random_state=1)print(lda.print_topics(num_topics=num_topics, num_words=10))ldacm = models.CoherenceModel(model=lda, texts=train, dictionary=dictionary, coherence='c_v')print(ldacm.get_coherence())return ldacm.get_coherence()

错误原因:一致性模型需要原始文本,而不是输入到LDA_Model的训练语料库

LDA主题模型中coherence(一致性)报错得出来为nan解决办法相关推荐

  1. 计算机开机故障报错,笔记本电脑开机报错故障的原因及解决办法

    笔记本电脑开机报错故障是指笔记本电脑开机自检时或启动操作系统前停止启动,在显示屏 出现一些错误提示的故障. 笔记本电脑开机报错故障的原因及解决办法 造成此类故障的原因一般是笔记本电脑在启动自检时,检测 ...

  2. 微信老是不能登录服务器错误,微信登录失败报错“4-100”的原因及解决办法

    微信登录失败报错"4-100"怎么办?微信是目前为止大家最喜欢的社交软件了,如果微信登录不了,整个人都不好了.最近就有用户遇到手机微信登录不了的情况,错误代码为"4-10 ...

  3. oracle pls 00905,【案例】Oracle报错PLS-00714 PLS-00951原因和解决办法笔记

    [案例]Oracle报错PLS-00714 PLS-00951原因和解决办法笔记 时间:2016-11-14 11:07   来源:Oracle研究中心   作者:代某人   点击: 次 天萃荷净 P ...

  4. Mac 升级后git pull 报错fatal: Authentication failed for 解决办法

    转载:Mac 升级后git pl 报错fatal: Authentication failed for 解决办法 - 简书 git pull,,,报错如下: cat .git/config git r ...

  5. 0x80070422报错、0x6D9报错,无法开启防火墙解决办法(方法版)

    0x80070422报错.0x6D9报错,无法开启防火墙解决办法 一.现象 现象1-报错0x80070422 现象2-报错0x6D9 二.解决方法 1.打开服务 2.打开防火墙服务 一.现象 现象1- ...

  6. Keras模型中数据维度报错

    ValueError: Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape 使 ...

  7. VirtualBox运行中经常报错0x00000000不能为written解决办法(附上所需文件下载链接)

    废话先不说,首先附上三个dll改好backup+破解恢复工具UniversalThemePatcher.exe的下载链接 https://pan.baidu.com/s/1OJD0j1ge20cHqS ...

  8. RT-Thread Studio中ST-LINK下载报错“Old ST-LINK firmware version“解决

    1.问题 RT-Thread Studio中选择ST-LINK下载,报错如下: 2.分析及解决步骤 这个报错是说ST-LINK的版本太老了,请升级. 首先报错没说找不到ST-LINK驱动啥的,只是说版 ...

  9. video.js在vue项目中设置中文语言包,报错videojs is not defined 解决办法

    在vue项目中使用video.js时要求中文化,但是网上的解决办法不太好找,特此记录一下. 错误步骤: 根据网上的教程,找到中文包在node_modules/video.js/dist/lang/zh ...

最新文章

  1. 通信系统之数字复接技术
  2. 计算机进制转换图,计算机等级考试进制转换及常用函数
  3. 【Linux】一步一步学Linux——fgrep命令(了解)(51)
  4. python迭代法求解非线性方程_荐【数学知识】非线性方程求解的二分法以及牛顿迭代法...
  5. Java—Iterator接口介绍及使用
  6. 将rm -f or -rf 删除命令改为放入回收站,并可通过命令将其撤回
  7. 小程序分享到朋友圈_微信内测开放小程序分享到朋友圈功能
  8. python一张图学懂_【python系统学习07】一张图看懂字典并学会操作
  9. 关于字符串匹配算法研究
  10. 移动端的人脸检测及去重算法实践
  11. Linux 动、静态库原理深剖
  12. 基于OpenCV的土壤裂缝分割系统
  13. DAY 2 Perceived and cognition || HTML CSS 入门
  14. 三款截图软件:Snipaste+FastStone-Capture+FireShot
  15. DeepCTR-Torch 如何使用【案例(Criteo、Movielens)演示、特征(SparseFeat、DenseFeat、VarLenSparseFeat)参数含义】
  16. python excel xlwngs 受保护的视图解除方法
  17. shell 文本替换命令
  18. kernel panic - not syncing : fatal exception
  19. 大象做梦传媒写2022年公司大型年会主持稿完整版
  20. Launcher功能入口

热门文章

  1. 贵州安酒投产12000吨开启新一年度酿酒工作
  2. 2021百度云存储面试
  3. 做短视频时自己的声音不好听,有没有让声音好听的办法?
  4. DSS代码解读-SRR_DSS_mmWaveTask(十三)
  5. 查询其他系中比计算机科学某一学生年龄小的学生姓名和年龄.,①查询其他系中比计算机科学(CS)某一学生年龄小的学生姓名和年龄。-桃子题库网...
  6. 《动手学深度学习》第二天
  7. Chapter1 我看空之轨迹
  8. Love is Blue
  9. ios中级面试题(二)
  10. Camera 原理总结