PHP Classes

PHP Benford's Law: Detect the probability of fraud in a data set

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (2)    
Last Updated Ratings Unique User Downloads Download Rankings
2023-10-09 (7 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 71 All time: 10,247 This week: 68Up
Version License PHP version Categories
phpbenfordslaw 1.0.0Free for non-comm...7Algorithms, Finances, Security, PHP 7
Description 

Author

This class can detect the probability of fraud in a data set.

It takes an array with data set value and applies Benford's Law algorithm to detect the probability of possible financial fraud.

The class can return the results of the probability of fraud as a percentage in three considering three levels of accuracy: low, medium, and high.

Innovation Award
PHP Programming Innovation award winner
October 2023
Winner
Fraud detection is critical to guarantee the security of transactions, especially when it involves financial values.

Benford's law can be applied to detect abnormal values in a data set that may contain financial values. This law can be used by analyzing the digits of a data set.

This package implements Benford's law in a PHP class. This way, PHP developers can apply it in applications to analyze values used in financial transactions to detect the probability of fraud quickly.

Manuel Lemos
Picture of Er. Rochak Chauhan
  Performance   Level  
Name: Er. Rochak Chauhan is available for providing paid consulting. Contact Er. Rochak Chauhan .
Classes: 54 packages by
Country: India India
Age: 45
All time rank: 21 in India India
Week rank: 71 Down7 in India India Down
Innovation award
Innovation award
Nominee: 15x

Winner: 4x

Instructions

1) Preprocess the data you want to check as a CSV of numbers.

2) Pass this file as input to the class, and using Benford's Law, this would detect if the data is possibly fraudulent or not.

Example

<?php
require("PhpBenfordsLaw.inc.php");


//Pre process all thef inancial or statistical numbersand create one simple array

//Sample Data as Array
//$financial_and_or_statistical_numbers = [4634,45,45745,34,4845,54,45847,484578458,424122458,45854,7845845,8548,458,45845,12142,8451118458458458,45548,124214,35311253,5312,3734865797,1231321,1151,9808,56,6,435412,1215151];
//$financial_and_or_statistical_numbers = [54068, 62230, 13680, 51852, 58747, 78644, 64645, 49661, 55402, 21759, 74357, 58409, 23753, 13620, 51658, 22702, 29723, 18556, 35766, 51943, 54112, 78911, 21008, 32474, 40681, 27638, 19005, 19446, 29326, 54414, 76864, 73764, 31107, 79526, 11094, 32609, 18796, 35321, 11057, 33829, 50154, 35746, 35319, 77618, 26742, 44634, 10426, 40880, 27044, 29841, 54597, 62444, 38001, 27553, 18364, 18565, 63128, 42329, 43225, 48359, 66263, 66907, 16677, 56920, 34748, 34500, 25112, 16149, 33405, 25266, 29751, 37862, 18322, 55153, 48674, 18251, 22323, 84013, 64157, 24744, 65587, 52532, 28558, 68720, 38537, 21512, 49704, 22676, 63964, 14423, 78619, 23305, 31240, 75304, 38443, 29345, 33775, 20878, 24354, 25310, 15921, 59167, 92712, 13764, 13368, 56035, 18090, 16989, 70712, 77927, 32835, 39870, 25986, 37677, 56368, 18662, 38750, 42417, 63895, 49116, 38946, 52507, 18230, 14380, 82850, 16084, 11568, 48467, 57949, 25738, 13567, 44094, 20905, 27310, 63686, 16634, 22497, 30345, 44809, 25497, 30801, 73688, 87845, 29584, 42168, 17834, 61278, 74603, 14156, 28222, 11149, 64895, 34471, 48448, 63183, 17591, 60490, 23687, 75807, 76896, 22937, 22478, 14250, 22783, 59767, 55487, 60611, 78318, 56546, 30302, 58798, 24474, 30007, 54272, 24140, 57522, 25157, 66152, 88646, 22951, 23737, 34745, 25397, 38715, 28931, 29373, 66199, 56721, 15861, 21172, 38808, 35877, 71952, 54826, 68351, 59099, 55834, 11000, 10812, 36928, 26742, 53304, 44575, 46045, 32019, 29579, 44718, 35270, 15761, 47507, 22463, 67906, 13804, 71326, 75597, 24971, 15712, 16672, 45011, 49578, 88009, 27235, 65061, 43077, 19192, 37670, 56370, 19127, 52563, 48183, 38994, 16442, 39667, 18172, 10896, 27945, 38517, 21405, 36356, 19356, 33314, 29193, 28945, 17241, 51289, 22812, 24521, 15642, 58860, 85034, 25704, 57957, 75081, 43644, 10271, 19705, 12232, 44120, 44392, 74763, 77070, 46411, 59474, 51384, 43520, 52758, 30619, 42826, 68486, 52916, 29031, 21120, 22458, 28872, 70058, 35627, 54821, 39085, 17957, 41270, 16743, 28741, 18084, 20257, 32060, 11377, 25089, 94187, 75600, 17914, 10854, 26659, 68055, 69583, 29838, 11269, 36877, 35635, 34587, 52691, 28138, 47131, 44056, 25404, 57405, 65035, 16968, 10225, 40657, 57849, 28808, 53864, 63219, 38564, 44293, 28633, 39232, 34107, 32677, 71513, 45529, 83511, 19563, 15583, 29017, 66541, 24882, 26467, 68525, 15968, 16260, 81891, 46366, 65138, 57896, 31763, 55435, 13574, 39956, 16018, 64927, 38998, 21912, 74246, 18300, 40683, 46744, 37267, 19157, 66912, 70016, 58449, 55030, 17909, 17458, 86066, 11641, 63095, 68069, 60887, 19162, 35547, 44158, 66565, 43797, 83050, 68710, 47639, 34676, 28522, 89487, 31476, 11546, 48003, 16490, 35723, 38552, 33482, 68988, 31681, 13275, 12816, 20766, 71397, 68719, 28522, 69209, 52273, 17443, 22525, 26833, 76045, 17843, 79203, 32769, 73392, 54823, 17196, 71339, 45529, 15259, 51875, 40816, 24663, 37245, 14352, 42752, 17763, 47421, 52826, 57525, 36916, 22573, 25953, 84971, 25973, 13165, 23782, 88369, 12334, 75942, 30699, 55371, 38141, 40537, 16369, 50769, 36146, 35556, 16740, 40161, 36099, 29237, 68873, 11698, 22194, 73770, 35215, 34177, 21965, 38222, 76293, 57000, 29831, 58329, 23834, 28348, 91047, 52334, 29642, 17816, 12529, 89548, 18438, 37530, 30938, 17732, 39276, 71907, 66526, 40181, 41465, 83691, 66555, 24371, 68476, 62543, 38674, 20551, 28271, 80658, 45934, 28507, 62755, 19773, 75463, 13471, 35940, 12587, 69631, 25931, 29451, 32009, 70717, 19523, 82337, 29727, 45029, 20712, 68210, 68255, 81425, 33743, 47010, 13413, 50522, 66661, 88012, 70576, 45002];


//PARSE CSV as Array
//$financial_and_or_statistical_numbers = file_get_contents("trial_balance_1.csv");
//$financial_and_or_statistical_numbers = explode("\r\n",$financial_and_or_statistical_numbers);

//PARSE CSV as Array
//$financial_and_or_statistical_numbers = file_get_contents("financial_data.csv");
//$financial_and_or_statistical_numbers = explode("\r\n",$financial_and_or_statistical_numbers);

$financial_and_or_statistical_numbers = file_get_contents("population_data.csv");
$financial_and_or_statistical_numbers = explode("\r\n",$financial_and_or_statistical_numbers);



$phpBenfordsLaw = New PhpBenfordsLaw($financial_and_or_statistical_numbers);


//Only for checking logic for small data
//$phpBenfordsLaw->debug();

$result = $phpBenfordsLaw->get_result("L");
echo
"<hr /> <pre> Benford's Law RESULT = "; print_r($result);
?>


Screenshots  
  • BenfordsLawGraph.png
  Files folder image Files  
File Role Description
Plain text file PhpBenfordsLaw.inc.php Class Main Class
Accessible without login Plain text file example.php Example example file
Accessible without login Plain text file financial_data.csv Data Sample data
Accessible without login Plain text file population_data.csv Aux. Sample data of Population
Accessible without login Plain text file trial_balance_1.csv Aux. Sample data of trial balance

 Version Control Unique User Downloads Download Rankings  
 0%
Total:71
This week:0
All time:10,247
This week:68Up