A library providing interactive plotting to benford-py
Project description
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; andL2D
: 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)
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file benfordviz-0.2.0.tar.gz
.
File metadata
- Download URL: benfordviz-0.2.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 086c5d35c9bd563609bb2fae008345a2d579fc64def6cee6be2cd97b23d98a3d |
|
MD5 | 0fac6a7ba544372d792efde3aa898ed8 |
|
BLAKE2b-256 | 8eedbbd33cc389496af1cd033328ee4c665e1c4bc88a1876f4d4259d67d5cf4c |
File details
Details for the file benfordviz-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: benfordviz-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 127dbc26d3ee6a0ca45553c73054714299505f06825c2df43bfcc2f93af28e6d |
|
MD5 | 71c57207516e13b02a6d656e310c6ae6 |
|
BLAKE2b-256 | 9a078996d51cc6ed567cbbabb13f5af920388541f19ab2ece33a7ff3c334b1ad |