[英]Plotting words frequency and NLTK
我有一個包含各種單詞的文件,我想計算文檔中每個單詞的頻率並繪制它。 但是,我的情節沒有顯示結果。 x-axis
必須包含單詞, y-axis
x-axis
必須包含頻率。 我正在使用NLTK
、 NumPy
和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()
file.txt
中的單詞列表:southbound
stopped
travel
lane
started
around
stopped
stopped
started
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.