FreqDist的问题

在看Python自然语言处理的时候,书中给出的代码跑出来结果和书里的不一样
fdist1 = FreqDist(text1) �
>>> fdist1 �
<FreqDist with 260819 outcomes>
>>> vocabulary1 = fdist1.keys() �
>>> vocabulary1[:50] ④
[',', 'the', '.', 'of', 'and', 'a', 'to', ';', 'in', 'that', "'", '-','his', 'it', 'I', 's', 'is', 'he', 'with', 'was',
'as', '"', 'all', 'for','this', '!', 'at', 'by', 'but', 'not', '--', 'him', 'from', 'be', 'on','so', 'whale', 'one',
'you', 'had', 'have', 'there', 'But', 'or', 'were','now', 'which', '?', 'me', 'like'] 

书中输出的成果是按照单词的频率由高至低排列的

但是跑这个代码是从书里的顺序排列的

又不想自己写逻辑

然后查到了这个点击打开链接

总的来说就是fdist1.tabulate()直接就可以获得一个从高到低的排列list

大概是这样


还有就是下面的画图, fdist1.plot(n)是从高到低的前n个单词的频率,fdist1.plot(50,cumulative=True)是积分的次数

反正和书里不一样

猜你喜欢

转载自blog.csdn.net/weixin_41965702/article/details/80858579