- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何使用 FreqDist 中的 fd.items() 来总结词频数?
>>> fd = FreqDist(text)
>>> most_freq_w = fd.keys()[:10] #gives me the most 10 frequent words in the text
>>> #here I should sum up numbers of each of these 10 freq words appear in the text
例如如果most_freq_w
中的每个词出现10次,结果应该是100
!!!我不需要文本中所有单词的数量,只需要最常见的 10 个
最佳答案
我不熟悉 nltk
,但由于 FreqDist
派生自 dict
,因此以下内容应该有效:
v = fd.values()
v.sort()
count = sum(v[-10:])
关于python - 使用FreqDist,python总结词频数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4206979/
我的目标是生成一个单词词典,在过去 3 年中具有不同的 FreqDist 键,但具有最新的出现时间。 我已经生成了一个字典,其中的键指的是日期,而值对应于当月提取的 FreqDist。 {'20151
我正在尝试分析应用评论中的一些数据。 我想使用 nltk 的 FreqDist 来查看文件中最常出现的短语。它可以是单个标记或关键短语。我不想对数据进行标记,因为这只会给我最常见的标记。但现在,Fre
当我尝试打印 FreqDist 对象时,我在打印结束时得到“...”?我尝试在 Internet 上查找它,但没有找到。 请让我知道哪里出错了。 代码: for word in nltk.word_t
在 NLTK 中,您可以轻松地计算文本中单词的计数,例如,通过执行以下操作 from nltk.probability import FreqDist fd = FreqDist([word for
我正在使用 NLTK 和 FreqDist().plot() 。但出于好奇,有没有办法将线图转换为直方图?以及如何在这两种情况下放置标签? 我在文档中进行了搜索,但遗憾的是它没有详细说明。 提前致谢
我尝试了不同的方法来保存我的情节,但我尝试过的每件事都出现了空白图像,而且我目前还没有没有想法。有其他可以解决此问题的建议吗?代码示例如下。 word_frequency = nltk.FreqDis
我正在尝试将单词列表(标记化字符串)分解为每个可能的子字符串。然后我想在每个子字符串上运行 FreqDist,以找到最常见的子字符串。第一部分工作正常。但是,当我运行 FreqDist 时,出现错误:
我正在尝试使用 Python 获取一组文档的频率分布。我的代码由于某种原因无法正常工作并产生此错误: Traceback (most recent call last): File "C:\Doc
我是 Python 的新手,我正在尝试自学语言处理。 python 中的 NLTK 有一个名为 FreqDist 的函数,它给出了文本中单词的频率,但由于某种原因它不能正常工作。 这是教程让我写的:
Python 包 nltk 具有 FreqDist函数为您提供文本中单词的频率。我正在尝试将我的文本作为参数传递,但结果是以下形式: [' ', 'e', 'a', 'o', 'n', 'i', 't
我有使用 NLTK 得到的频率分布: [(('ingeniería', 'informática'), 30), (('tecnologías', 'información'), 26), (('si
我有一个包含两列 id 和 text 的数据框 我想添加一个新列,其中包含每行文本的字数。 我创建了一个 userdefinedFunction,其中我从 nltk 实现了 word_tokenize
我是 Python 和 NLTK 的初学者。我正在尝试运行教程中的以下代码: from nltk.corpus import gutenberg from nltk import FreqDist f
我有一个小程序,它使用 NLTK 来获取相当大的数据集的频率分布。问题是,几百万字后,我开始耗尽系统上的所有 RAM。以下是我认为相关的代码行: freq_distribution = nltk.Fr
我正在学习 NLTK 和我的 mac 工作正常,除非我在 FreqDist() 上遇到问题。 (我看到另一个关于 FreqDist() 的问题,但他收到了不同的错误消息。TypeError: unha
我正在玩弄 NLTK 和模块 freqDist import nltk from nltk.corpus import gutenberg print(gutenberg.fileids()) fro
我想计算文本语料库中单词的词频。我一直在使用 NLTK 的 word_tokenize 后跟 probability.FreqDist 一段时间来完成这项工作。 word_tokenize 返回一个列
nltk.FreqDist('abc') > nltk.FreqDist('abd') 返回 True 和 nltk.FreqDist('abd') >> abc = nltk.FreqDist('a
我是一名优秀的程序员,十分优秀!