DrDigit
DrDigit is a digit doctoring detection package at an early stage. Interested in contributing? Please feel free to contact me, e.g. by commenting on the issue "Contributors welcome!" at https://github.com/brezniczky/drdigit/issues/1.
Requirements
DrDigit requires Python 3.5 or later.
Concept
The tests are based on the statistics of digits which are assumed to have a uniform distribution. Near-uniform distributions can be obtained by looking at the last digits of sufficiently large values - such as vote counts (possibly above 100).
On a smaller scale, you can query for the probablity of a digit sequence using probability mass functions represented by Python functions.
There are larger scale tests for a sequence of digit groups. This is so to support situations where different groups are expected to be doctored by different people - testing for an overarching, consistent anomaly could be too strict in such cases.
Based on the current features (entropy, digit repetition, coincident digits in parallel sequences), it is possible to sort a data frame containing digit groups by probability, so then it is possible to inspect if there is any apparent sanity behind the doctoring.
A couple of hints
-
Handle results with care, there is always some uncertainity
-
Try to focus on interesting groups, this should yield much sharper results
-
When committing Kaggle scripts, switch off the on-disk caching of tests before committing, e.g. via
import drdigit as drd drd.set_option(physical_cache_path="")You can find more about it via
help(drd.set_option).
Quick start
DrDigit can be installed using pip:
$ pip install drdigit-brezniczky
$ ipython
Digit entropy behaves a little weirdly when different digit sequence lengths are considered - isn't the sequence 1, 2 as diverse as possible?
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.7.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import drdigit as drd
In [2]: help(drd)
In [3]: print(drd.get_entropy([1, 2]))
0.6931471805599453
In [4]: print(drd.get_entropy([1, 1, 2, 2]))
0.6931471805599453
Probabilities are often more suited for a comparison:
In [6]: drd.prob_of_entr(2, drd.get_entropy([1, 2]))
cdf for 2 was generated
Out[6]: 1.0
In [7]: drd.prob_of_entr(4, drd.get_entropy([1, 1, 2, 2]))
cdf for 4 was generated
Out[7]: 0.0624
Indeed, the latter sequence is unusually repetitive.
More examples to follow, for now you can have a look at the Kaggle notebook at
https://www.kaggle.com/brezniczky/poland-2019-ep-elections-doctoring-quick-check
or around
https://github.com/brezniczky/ep_elections_2019_hun/blob/master/PL/
for instance in the process_data.py file.
Some complicated (and - sorry, sometimes unreliabe/slightly outdated) details about the considerations/methodology and future ideas can be found in the Hungarian elections document
Tests
The few tests that there are can be run by pytest.
For this, I would just use virtualenvwrapper and do something akin to
$ mkvirtualenv drdigit_test
$ pip install -r requirements/requirements_test.txt
$ pytest
from the directory of the drdigit clone.
Metadata
Release files for drdigit-brezniczky 0.0.17
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 |
|---|---|---|---|---|
| drdigit-brezniczky-0.0.17.tar.gz | 26.2 kB | Without provenance | Details for drdigit-brezniczky-0.0.17.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drdigit_brezniczky-0.0.17-py3-none-any.whl | Python 3 | none | any | Details for drdigit_brezniczky-0.0.17-py3-none-any.whl |
Total release size: 68.1 kB
Release files / drdigit-brezniczky-0.0.17.tar.gz
| Download URL | drdigit-brezniczky-0.0.17.tar.gz |
|---|---|
| Size | 26.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cb0f01994a0e67f816658fc4e1a497ecee8a704d0d5b90519f828f9b3160d771
|
|
BLAKE2b-256 checksum How to use checksums |
9d35d1d043148b75334a158c7f8ade825883007bb8c499957d16dd3fb853ece0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.5.2
|
Release files / drdigit_brezniczky-0.0.17-py3-none-any.whl
| Download URL | drdigit_brezniczky-0.0.17-py3-none-any.whl |
|---|---|
| Size | 41.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db2801c1863cc4a9eb7ab7125e5e841c4c3542efec69714b2a8b3127659d6a16
|
|
BLAKE2b-256 checksum How to use checksums |
bd9d600e72e76cdd7ef3d7185f026669ad46f05a5eb00b872c492e0ebeb6b0b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.5.2
|
Security for drdigit-brezniczky 0.0.17
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.