- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在 NLTK 中,您可以轻松地计算文本中单词的计数,例如,通过执行以下操作
from nltk.probability import FreqDist
fd = FreqDist([word for word in text.split()])
其中文本是一个字符串。现在,您可以将分布绘制为
fd.plot()
这将为您提供一个漂亮的线图,其中包含每个单词的计数。在docs没有提到绘制实际频率的方法,您可以在 fd.freq(x)
中看到。
有什么直接的方法可以绘制归一化计数,无需将数据放入其他数据结构,单独进行归一化和绘图?
最佳答案
您可以使用 fd[word]/total 更新 fd[word]
from nltk.probability import FreqDist
text = "This is an example . This is test . example is for freq dist ."
fd = FreqDist([word for word in text.split()])
total = fd.N()
for word in fd:
fd[word] /= float(total)
fd.plot()
注意:您将丢失原始的 FreqDist 值。
关于python - NLTK FreqDist,绘制归一化计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38617172/
我的目标是生成一个单词词典,在过去 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
我是一名优秀的程序员,十分优秀!