Benford's law analysis
Benford's law is a digit-law, which states that digits from numbers follow a specific frequency. This specific frequency has been observed in many numerical datasets, as discovered by Simon Newcomb and Frank Benford. You can find on wikipedia more information about this mysterious law.
Benford's law is a helpful tool to detect fraud, do science, or just investigate the quality of data. You can also read my blog on Towards Data Science with a summary of Benford's law and this paper, where I used Benford's law to study digit patterns of the distances between stars in our Milky Way.
Installation
With pip install benfordslaw-analysis you can install the package.
Usage
After installing, you can run in Python from benfordslaw_analysis.analysis import Analysis.
This imports the class Analysis.
With this class you can verify if Benford's law is hidden in your own data.
For example, make a plot with Benford's law versus random data with:
from benfordslaw_analysis.analysis import Analysis
from random import uniform
random_data = [uniform(-10, 10) for i in range(0,1000)]
bl = Analysis(random_data)
bl.plot_first_digit('Random stuff')
Note that we use the Euclidean distance between the digit frequency from Benford's law and your own data as a measure and that we use Poisson error bars (based on the number of data points).
Euclidean distance
The normalized Euclidean distance is a quick way to test whether your data follows Benford law. This value is situated between 0 and 1, the closer to 0 the better. However, it is not a formal statistic because it is sample size independent. In the literature there are several other measures (Chi-square, Kolmogorov-Smirnov, ..) that are used. However, I noticed in my own research that size dependency is a limitation in bigger datasets and classifies all bigger datasets as non-Benford, even though they are Benford by eye.
Citing
If you find benfordslaw_analysis a useful tool for your own research, please cite in the following way:
@misc{benford_py,
author = {Jurjen, de Jong},
title = {{benfordslaw_analysis: a Python Implementation of Benford's Law analysis}},
year = {2021},
howpublished = {\url{https://github.com/jurjen93/Benfords_law}},
}
Metadata
Release files for benfordslaw-analysis 1.1.0
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 |
|---|---|---|---|---|
| benfordslaw_analysis-1.1.0.tar.gz | 4.4 kB | Without provenance | Details for benfordslaw_analysis-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| benfordslaw_analysis-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for benfordslaw_analysis-1.1.0-py3-none-any.whl |
Total release size: 9.3 kB
Release files / benfordslaw_analysis-1.1.0.tar.gz
| Download URL | benfordslaw_analysis-1.1.0.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04a1dfd9b29bda6a0cd707fe37a0a8c032851482d521835a850971bbf83a1c00
|
|
BLAKE2b-256 checksum How to use checksums |
d61b76d0357efeeea8cbfbcb673e765bcbe4829d5bca199728dcd018ddb1ecf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/65.6.3 requests-toolbelt/0.8.0 tqdm/4.66.1 CPython/3.8.10
|
Release files / benfordslaw_analysis-1.1.0-py3-none-any.whl
| Download URL | benfordslaw_analysis-1.1.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bbe2925d4c77531117d0c8c539b59288db6e91dfa338f9f64e7828ba99f9a0b7
|
|
BLAKE2b-256 checksum How to use checksums |
b44176bbeb55d6797b4c85e89865473b08061303b40d09504d1bff7555836206
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/65.6.3 requests-toolbelt/0.8.0 tqdm/4.66.1 CPython/3.8.10
|
Security for benfordslaw-analysis 1.1.0
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.