Python 使用nltk绘制50个最不频繁的单词
我如何绘制50个最不常用的单词 也许我的想法太复杂了。我是这样理解的:Python 使用nltk绘制50个最不频繁的单词,python,plot,nlp,nltk,Python,Plot,Nlp,Nltk,我如何绘制50个最不常用的单词 也许我的想法太复杂了。我是这样理解的: distr = nltk.FreqDist(word for word in items) words = distr .keys() seldomwords = words [:50] 我现在该怎么画呢 通过FreqDist的plot功能,我获得了所有或仅x个最频繁的单词 我试过这样的方法: distr .plot(:50) 但这在语法上是不正确的。这有点奇怪,但最简单的方法是 首先,您必须从FreqDist 然后重
distr = nltk.FreqDist(word for word in items)
words = distr .keys()
seldomwords = words [:50]
我现在该怎么画呢
通过FreqDist
的plot
功能,我获得了所有或仅x个最频繁的单词
我试过这样的方法:
distr .plot(:50)
但这在语法上是不正确的。这有点奇怪,但最简单的方法是
- 首先,您必须从
FreqDist
- 然后重新创建最不常见的项,并将其反馈到新的FreqDist对象中
- 使用新的FreqDist命令使用
FreqDist.plot()
>>> from nltk import FreqDist
>>> fd = FreqDist(list('aaabbbbbcccccdddddddd'))
>>> last_two = FreqDist(dict(fd.most_common()[-2:]))
>>> last_two.plot()
>>> from nltk import FreqDist
>>> fd = FreqDist(list('aaabbbbbcccccdddddddd'))
>>> last_two = FreqDist(dict(fd.most_common()[-2:]))
>>> last_two.plot()
>>> last_three = FreqDist(dict(fd.most_common()[-3:]))
>>> last_three.plot()
[out]:
[代码]:
>>> from nltk import FreqDist
>>> fd = FreqDist(list('aaabbbbbcccccdddddddd'))
>>> last_two = FreqDist(dict(fd.most_common()[-2:]))
>>> last_two.plot()
>>> from nltk import FreqDist
>>> fd = FreqDist(list('aaabbbbbcccccdddddddd'))
>>> last_two = FreqDist(dict(fd.most_common()[-2:]))
>>> last_two.plot()
>>> last_three = FreqDist(dict(fd.most_common()[-3:]))
>>> last_three.plot()
[out]:
这有点奇怪,但最简单的方法是
- 首先,您必须从
FreqDist
- 然后重新创建最不常见的项,并将其反馈到新的FreqDist对象中
- 使用新的FreqDist命令使用
FreqDist.plot()
>>> from nltk import FreqDist
>>> fd = FreqDist(list('aaabbbbbcccccdddddddd'))
>>> last_two = FreqDist(dict(fd.most_common()[-2:]))
>>> last_two.plot()
>>> from nltk import FreqDist
>>> fd = FreqDist(list('aaabbbbbcccccdddddddd'))
>>> last_two = FreqDist(dict(fd.most_common()[-2:]))
>>> last_two.plot()
>>> last_three = FreqDist(dict(fd.most_common()[-3:]))
>>> last_three.plot()
[out]:
[代码]:
>>> from nltk import FreqDist
>>> fd = FreqDist(list('aaabbbbbcccccdddddddd'))
>>> last_two = FreqDist(dict(fd.most_common()[-2:]))
>>> last_two.plot()
>>> from nltk import FreqDist
>>> fd = FreqDist(list('aaabbbbbcccccdddddddd'))
>>> last_two = FreqDist(dict(fd.most_common()[-2:]))
>>> last_two.plot()
>>> last_three = FreqDist(dict(fd.most_common()[-3:]))
>>> last_three.plot()
[out]:
看一看,看一看,这就是我要找的。谢谢这就是我要找的。谢谢