-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""''' | ||
39. Zipfの法則 | ||
単語の出現頻度順位を横軸,その出現頻度を縦軸として, | ||
両対数グラフをプロットせよ.''' | ||
|
||
import math | ||
from knock30 import load_result | ||
from knock35 import sort_frequency | ||
import matplotlib.pyplot as plt | ||
import japanize_matplotlib | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
mecabfile = '../data/neko.txt.mecab' | ||
nekodata = load_result(mecabfile) | ||
ans = sort_frequency(nekodata) | ||
|
||
|
||
ranks = [r + 1 for r in range(len(ans))] | ||
cnts = [i[1] for i in ans] | ||
plt.figure(figsize=(8, 4)) | ||
plt.scatter(ranks, cnts) | ||
plt.xscale('log') | ||
plt.yscale('log') | ||
plt.xlabel('出現頻度順位') | ||
plt.ylabel('出現頻度') | ||
plt.show() |