I'm trying to use feature hashing (or hashing trick) on a set of files that are composed mostly in English and code (in English).
I'm trying to see if Zipf's law applies to the set of files before I try to use feature hashing.
Looking at 3 different websites:
- https://en.wikipedia.org/wiki/Zipf's_law
- How to calculate Zipf's law coefficient from a set of top frequencies?
- How to verify if data follows Zipf's law without looking at the graph
It seems that I would need to:
- Plot a rank vs Occurrences graph
- Apply log_10 to rank and occurences, and see if there is some sort of linear line
- Use Linear Regression to construct a line, and look at the residuals.
- Use Chi-Squared Test to see how the fit is doing.
So here I go:
- Plot a rank vs Occurrences graph
Okay, so it looks a bit like power distribution.
- Apply log_10 to rank and occurences, and see if there is some sort of linear line
Hmm... It doesn't really fit the graph found on wikipedia, but the middle part looks okay.
- Use Linear Regression to construct a line
- Chi Squared Value:
Using scipy, I was able to get some sort of numbers:
statistic=-5231551.8602747163, pvalue=1.0
I see that from graph 1, 2, and 3, it looks like Zipf's law might not hold. And looking at 4, I'm not too sure what it means.
Then I'm stuck, because I get all these graphs and numbers, but I'm not sure how to programmatically determine if I can use feature hashing?
If we compare it to something like skewness, we can compute some sort of number for skewness, if > 0, then it means it's skewed to the left, and vice versa.