Skip to main content

benfordviz

Interactive plotting to benford_py.

This is a lib to make interactive plotting of Benford's Law Tests easier.

Citing

If you find benfordviz useful in your research, please consider adding the following citation:

@misc{benfordviz,
      author = {Marcel, Milcent},
      title = {{Benfordviz: a Python Implementation of interactive plotting for Benford's Law Tests}},
      year = {2021},
      publisher = {GitHub},
      journal = {GitHub repository},
      howpublished = {\url{https://github.com/milcent/benfordviz}},
}

current version = 0.2.0

See release notes for details of features and bugs.

Python versions >= 3.6

Installation

pip install benfordviz

Dependencies

  • benford_py >= 0.4.2;
  • bokeh >= 2.3.2

Implemented so far:

  • Bokeh
  • More in the furure - let me know which one you prefer implemented next in the Issues. Plotly? Altair?

Usage

Have your data ingested in a benford_py Benford obect like so:

import numpy as np
import benford as bf

# Benford's sets are combinations of random variables
a = np.random.rand(3000)
b = np.random.randint(0,55, 3000)
c = np.random.normal(3000)
abd = a * b * c

bo = bf.Benford(abc)
 ########## Benford Object Instantiated ########### 

Initial sample size: 3000.

Test performed on 2941 registries.

Number of discarded entries for each test:
{'F1D': 0, 'F2D': 0, 'F3D': 0, 'SD': 0, 'L2D': 1}

Now that you have a Benford object with the main tests already computed, you can give them to benfordviz and let it do the rest. The main function for plotting the respective test with bokeh is the bokeh_chart. It receives a digit test instance, which in turn is an attribute of the Benford object:

  • F1D: First Digit Test;
  • SD: Second Digit Test;
  • F2D: First Two Digits Test;
  • F3D: First Three Digits Test; and
  • L2D: Last Two Digits Test.

The bokeh_chart function then retuns a bokeh figure, which you can then pass to the output of your choice (browser, file, jupyter...)

from bokeh.plotting import output_notebook, show
from benfordviz import bokeh_digits_chart

output_notebook()

# plotting the First Two Digits Test ('F2D')
benf_bokeh_f2d_fig = bokeh_digits_chart(bo.F2D)
show(benf_bokeh_f2d_fig)

First Two Digits Bokeh gif

Or you can directly instantiate a BokehDigitsChart object, and use its figure, like so:

from benfordviz.bokeh_plotting import BokehDigitsChart

bdc_f2d = BokehDigitsChart(bo.F2D)
show(bdc_f2d.figure)

As of version 0.2.0, we also have the Manitssas Tests chart, which is a union of the Ordered Mantissas and the Mantissas Arc Plots, side-by-side. Since the mantissas assessment is made on the whole set (not segregated by digits), you can pass the Benford instance directly to it.

from benfordviz import bokeh_mantissas_chart

benf_bokeh_mant_fig = bokeh_mantissas_chart(bo) 
show(benf_bokeh_mant_fig)

First Two Digits Bokeh gif

Metadata

Release files for benfordviz 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for benfordviz 0.2.0
File Size Uploaded Provenance Actions
benfordviz-0.2.0.tar.gz 9.8 kB Without provenance Details for benfordviz-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for benfordviz 0.2.0
File Interpreter ABI Platform Actions
benfordviz-0.2.0-py3-none-any.whl Python 3 none any Details for benfordviz-0.2.0-py3-none-any.whl

Total release size: 19.5 kB

Release files / benfordviz-0.2.0.tar.gz

Download URL benfordviz-0.2.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
086c5d35c9bd563609bb2fae008345a2d579fc64def6cee6be2cd97b23d98a3d
BLAKE2b-256 checksum
How to use checksums
8eedbbd33cc389496af1cd033328ee4c665e1c4bc88a1876f4d4259d67d5cf4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

Release files / benfordviz-0.2.0-py3-none-any.whl

Download URL benfordviz-0.2.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
127dbc26d3ee6a0ca45553c73054714299505f06825c2df43bfcc2f93af28e6d
BLAKE2b-256 checksum
How to use checksums
9a078996d51cc6ed567cbbabb13f5af920388541f19ab2ece33a7ff3c334b1ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

Security for benfordviz 0.2.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page