zipfanalysis
Tools in python for analysing Zipf’s law from text samples.
This can be installed as a package from the python3 package library using the terminal command:
>>> pip3 install zipfanalysis
Usage
The package can be used from within python scripts to estimate Zipf exponents, assuming a simple power law model for word frequencies and ranks. To use the pacakge import it using
import zipfanalysis
Simple Method
The easiest way to carry out an analysis on a book or text file, using different estimators, is:
alpha_clauset = zipfanalysis.clauset("path_to_book.txt")
alpha_pdf = zipfanalysis.ols_pdf("path_to_book.txt", min_frequency=3)
alpha_cdf = zipfanalysis.ols_cdf("path_to_book.txt", min_frequency=3)
alpha_abc = zipfanalysis.abc("path_to_book.txt")
In Depth Method
Convert a book or text file to the frequency of words, ranked from highest to lowest:
word_counts = zipfanalysis.preprocessing.preprocessing.get_rank_frequency_from_text("path_to_book.txt")
Carry out different types of analysis to fit a power law to the data:
# Clauset et al estimator alpha_clauset = zipfanalysis.estimators.clauset.clauset_estimator(word_counts) # Ordinary Least Squares regression on log(rank) ~ log(frequency) # Optional low frequency cut-off alpha_pdf = zipfanalysis.estimators.ols_regression_pdf.ols_regression_pdf_estimator(word_counts, min_frequency=2) # Ordinary least squares regression on the complemantary cumulative distribution function of ranks # OLS on log(P(R>rank)) ~ log(rank) # Optional low frequency cut-off alpha_cdf = zipfanalysis.estimators.ols_regression_cdf.ols_regression_cdf_estimator(word_counts) # Approximate Bayesian computation (regression method) # Assumes model of p(rank) = C prob_rank^(-alpha) # prob_rank is a word's rank in an underlying probability distribution alpha_abc = zipfanalysis.estimators.approximate_bayesian_computation.abc_estimator(word_counts)
Development - Next Steps
Speed up abc. Current bottleneck is sampling from infinite power law. Could be sped up by considering we only need the frequency vector of ranks, not the whole sample. So for example could sample from unoform distribution then drop values into interger ranked buckets based on inverse CDF.
Build in frequency rank analysis. Convert to frequency counts representation, then carry out fit on that.
Add significance testing
Add ability to calcaulte x_min and truncated power laws.
Speed up OLS on the cdf
Metadata
Release files for zipfanalysis 0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zipfanalysis-0.5.tar.gz | 9.2 kB | Without provenance | Details for zipfanalysis-0.5.tar.gz |
Release files / zipfanalysis-0.5.tar.gz
| Download URL | zipfanalysis-0.5.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
632d7ee817a0730a4f4566dde60296dc15fc9fd56070e19be2bf8f253b846742
|
|
BLAKE2b-256 checksum How to use checksums |
608f793fe0b3ff2cc62684d58ac8fa32dba2e24a0ca7509a09988773b7f4656c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9
|
Security for zipfanalysis 0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.