How do I measure or find the Zipf distribution ? For example, I have a corpus of english words. How do I find the Zipf distribution ? I need to find the Zipf ditribution and then plot a graph of it. But I am stuck in the first step which is to find the Zipf distribution.
Edit: From the frequency count of each word, it is clear that it obeys the Zipf law. But my aim is to plot a zipf distribution graph. I have no idea about how to calculate the data for the distribution graph
I don't pretend to understand statistics. However, based upon reading from scipy site, here is a naive attempt in
python
.Build Data
First we get our data. For example we download data from National Library of Medicine MeSH (Medical Subject Heading) ASCII file d2016.bin (28 MB).
Next, we open file, convert to string.
Next we locate individual words in the file and separate out words.
Finally we prepare a dict with unique words as key and word count as values.
Build zipf distribution data
For speed purpose we limit data to 1000 words.
After that we get frequency of values , convert to
numpy
array and usenumpy.random.zipf
function to draw samples from azipf
distribution.Distribution parameter
a =2.
as a sample as it needs to be greater than 1. For visibility purpose we limit data to 50 sample points.And finally plot the data.
Putting All Together
Plot