Giter Club home page Giter Club logo

benford's Introduction

A Python package to apply the Benford´s Law analysis

Project Motivation

As part of the Udacity Data Science nanodegree this is a project to create and deploy a Python package, based on this I decided to use the Benford´s Law to create a package using OOP than can apply the analyzis to a dataset, an imgae or a numpy array of numbers.

Installation:

pip intall benford_law

This package uses these libraries

  • pandas
  • numpy
  • matplotlib

The python version used: 3.8

Files in the repository

  • README.md : This file
  • setup.py : Setup file for the package
  • .gitignore : File to ignore files and not load to the GitHub repository
  • LICENSE : The MIT License
  • benford_law
    • bendord_law.py : The Benford Class
    • init.py : Inititalization file for the package
  • tests
    • tests.py : Script for unit tests of the Benford Class
    • Benford_plot_test.ipynb : Jupyter Notebook to test the graphs plotting ot the Benford Class
    • flower.jpg : JPG image to test the Benford Class
    • population.csv : CSV dataset with the Wordl Population to test the Benford Class

How To use the package

  1. Create an instace with the Benford Class

    • benford = Benford()
  2. Load a dataset or an image ,

    • bendford.load_dataset(dataset_name)
    • benford.load_image(image_name)
  3. Do the benford analysis using the benford_analysis method

    • benford.benford_analysis()
  4. Graph or plot the results using plot() method

    • benford.plot()
  5. Save the results using expor_to_csv() method:

    • benford.export_to_csv(filename)

Example using the pakage to analyze an image:

#Import libraries
import pandas as pd
import numpy as np
from benford_law import Benford
import matplotlib.pyplot as plt
from PIL import Image


image_file = 'flower.jpg'      #Read image
image = Benford()              #Create Benford instance
image.load_image(image_file)   #Load image
image.benford_analysis()       #Do Analysis
image.plot()                   #Plot Benford´s analysis

Apply the Benford´s Law analysis to this image:

Example

Example

Terms of use:

This is a tool to do an initial analyzis using Benford´s Law and plot how the digit´s probability are distributed on different datasets, it is not a formal analysis or study using the Benford´s Law

License:

The code follows this license: https://opensource.org/licenses/MIT

benford's People

Contributors

rafaelmata357 avatar

Stargazers

Matic Conradi avatar Jay Vala avatar Tobias Schmidbauer avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

xorcpp leungrhy

benford's Issues

Problem loading dataset

Hi - I get the following error when I try to lad the dataset:

--> 243 raise ValueError(msg)
244
245 return filepath_or_buffer, None, compression, False

ValueError: Invalid file path or buffer object type: <class 'pandas.core.frame.DataFrame'>`

My dataset is standard Pandas dataframe with only float formats with all valid values.

Image analysis - enough orders of magnitude?

Hello, I'm exploring Benford's Law myself and ran across your library. I had a question about the way you are doing images, specifically the load_image method. I see that, for an RGB image, it's basically analyzing the R, G, and B values for each pixel. That would mean the max value in the distribution is 255. Is that enough orders of magnitude for Benford's Law to apply?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.