我有一个包含各种单词的文件,我想计算文档中每个单词的频率并绘制它。
但是,我的情节没有显示结果。
这x-axis
必须包含单词,并且y-axis
频率。
我在用NLTK
, NumPy
and Matplotlib
这是我的代码,也许我做错了什么
def graph():
f = open("file.txt", "r")
inputfile = f.read()
words = nltk.tokenize.word_tokenize(inputfile)
count = set(words)
dic = nltk.FreqDist(words)
FreqDist(f).plot(50, cumulative=False)
f.close()
southbound
stopped
travel
lane
started
around
stopped
stopped
started
import nltk
def graph():
with open("file.txt", "r") as f:
inputfile = f.read()
tokens = nltk.tokenize.word_tokenize(inputfile)
fd = nltk.FreqDist(tokens)
fd.plot(30,cumulative=False)
graph()
您可以通过更改plot()的参数来玩弄图表
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)