ITECH1400 Foundations of Programming Logarithms, Benford’s Law and Fraudulent Data Overview In this assignment you will write an application in Python that will apply Benford’s Law to a given set of...

1 answer below »
phyton


ITECH1400 Foundations of Programming Logarithms, Benford’s Law and Fraudulent Data Overview In this assignment you will write an application in Python that will apply Benford’s Law to a given set of your own data. This is an individual assignment. Timelines and Expectations Percentage Value of Task: 20% Due: Friday 29 May 2020 @17:00 (week 11) Minimum time expectation: 20 hours Learning Outcomes Assessed The following course learning outcomes are assessed by completing this assessment: K1. Identify and use the correct syntax of a common programming language. K2. Recall and use typical programming constructs to design and implement simple software solutions. K3. Reproduce and adapt commonly used basic algorithms. K4. Explain the importance of programming style concepts (documentation, mnemonic names, indentation) S2. Write and implement a solution algorithm using basic programming constructs. S3. Demonstrate debugging and testing skills whilst writing code. A1. Develop self-reliance and judgement in adapting algorithms to diverse contexts. A2. Design and write program solutions to identified problems using accepted design constructs. Assessment Details CRICOS Provider No. 00103D 1400 Assig 2, 2020-05 2 Background At the turn of the century, if you wanted to do some serious calculating you usually used a book of logarithms1 to help you do the arithmetic; the pages in the book of logarithms were arranged in numerical order. A sample logarithms page, from the link below, is shown here on the right. An astronomer, Simon Newcomb, noticed that the pages at the beginning of the book were much more worn than those at the back of the book - which were hardly used at all – much like that shown in the picture of a well-thumbed book below. Newcomb noticed that the leading digits, of all the numbers used in his calculations, were more likely to be small digits rather than large digits. Newcomb published a note2 about this and nothing more was heard about it – this was in1881. Intuitively most people still felt that the digits 1 - 9 were evenly distributed in all numbers. However, in 1937, a physicist by the name of Frank Benford, discovered Newcomb’s idea and set about testing this idea using over 20,000 different sets of data such as: lengths of rivers, street addresses, death rates, 1 https://www.wikiwand.com/en/Common_logarithm 2 Newcomb, S. (1881). Note on the Frequency of Use of the Different Digits in Natural Numbers. American Journal of Mathematics, 4(1), 39-40. https://www.wikiwand.com/en/Common_logarithm CRICOS Provider No. 00103D 1400 Assig 2, 2020-05 3 sports statistics, molecular weights and so on – and it is base and scale invariant – the length of rivers could be in miles, kilometres, metres or even cubits. Theory Although you do not need to know the derivation3 or proof of Benford’s law, all you need to know is how to apply it to a set of data. Benford’s law states4: 1 1 1 1 10 1 Pr( ) log (1 ) d {1,2,...,9}dD d    (Equation 1) So that, for the first digit in a number, the probability that this digit is a ‘1’ is: or about 30.1%. Similarly for the remaining digits 2-9. If we do this for all the digits and plot them as a bar graph, we get: 3 See, for example, Miller, S. J. (2015). A Quick Introduction to Benford’s Law. In S. J. Miller (Ed.), Benford's Law (pp. 3-22): Princeton University Press. 4 Nigrini, M. J., & ProQuest (Firm). (2012). Benford's law applications for forensic accounting, auditing, and fraud detection, Wiley corporate F & A, p.5 CRICOS Provider No. 00103D 1400 Assig 2, 2020-05 4 Your Task Develop a Python program which will load up a set of data, determine the frequencies of the leading digits and compare them with the predicted distribution of Benford’s law. Display this in a bar chart and a table of values. For example: Digit 1: Observed = 0.321 Expected = 0.301 Digit 2: Observed = 0.153 Expected = 0.176 and so on up till digit 9. We shall look at three cases. An Excel spreadsheet has been taken from Office-Watch: Benford’s Law and Excel5 to let you quickly visualize the Python application that we need make. Case 1 - Fibonacci series6 This series begins with two numbers 1,1 – these two numbers are added to continue the series giving rise to the following (only the first 8 terms of the series are shown here): 1,1,2,3,5,8,13,21,. . . There are many examples of this pattern in Nature and the series is closely related to the Golden7 ratio. Using the Excel spreadsheet generate a Fibonacci series up to the 24th term and see if the first digits obey Benford’s Law. Does it get better if you add more terms? The Chi-test8 measures how close an actual value is to the expected value – the closer it is to 100% the closer the actual value is to the expected value. In our case, we are testing how close the frequency of each digit in our dataset is to Benford’s prediction for that digit. What is the value of the ChiTest comparison for this Fibonacci series? Does it get better if we add more terms to the series? Case 2 – Fibonacci numbers & Benford’s law using Python In this case you are to repeat the analysis in Case 1 but using you Python code. 5 https://office-watch.com/2012/benfords-law-and-excel/ 6 https://en.wikipedia.org/wiki/Fibonacci_number 7 https://en.wikipedia.org/wiki/Golden_ratio 8 Also written as 2-test https://office-watch.com/2012/benfords-law-and-excel/ https://en.wikipedia.org/wiki/Fibonacci_number https://en.wikipedia.org/wiki/Golden_ratio CRICOS Provider No. 00103D 1400 Assig 2, 2020-05 5 Case 3 – Length of Rivers9 in the World In this case, use your Python code to see whether the lengths of rivers in the world follow Benford’s law. Fraud detection using Benford’s Law One use of Benford’s Law is to detect cases of Fraud. Consider the 1993 case of State of Arizona v Nelson. The accused diverted nearly $2M to fake vendors in an attempt to defraud the State. The frequency of first digits in the written cheques clearly violates Benford’s Law leading to a conviction. Another case is that of Enron in its posting of revenue for the year 2000. Comparison of the frequency of first digits versus the expected frequency shows large discrepancies. The company went bankrupt the following year – one of the greatest financial failures in history. 9 https://en.wikipedia.org/wiki/List_of_rivers_by_length https://en.wikipedia.org/wiki/List_of_rivers_by_length CRICOS Provider No. 00103D 1400 Assig 2, 2020-05 6 Submission A report is to be submitted in this assignment. There is a discussion section in the report in which you can apply step 6 in the six-step problem solving process and ask the four questions often used in evaluating a solution. More details on academic reports are available - please refer to this link: https://federation.edu.au/current-students/learning-and-study/online-help-with/guides-to-your- assessments There are three important parts at the link above: 1. General Guide to Writing and Study Skills This section describes the content of a report – refer to page 34 – Abstract, Table of Contents, Introduction and Conclusion and so on. 2. General Guide to Referencing APA referencing style is described in this section – EndNote is also available to students 3. Assignment Layout and Appearance Guidelines This section describes how the report should appear: margin sizes, fonts, how diagrams and tables are presented and so on. You must supply your program source code files and your documentation, together with any files required to run your application, as a single zip file named as follows:_.zip e.g. Ada_LOVELACE_30331815.zip You may supply your word processed documentation in either Microsoft Word or LibreOffice/OpenOffice formats only – no proprietary Mac specific formats, please. Assignments will be marked on the basis of fulfilment of the requirements and the quality of the work. In addition to the marking criteria, marks may be deducted for failure to comply with the assignment requirements, including (but not limited to): • Incomplete implementation(s), and • Incomplete submissions (e.g. missing files), and • Poor spelling and grammar. You might be asked to demonstrate and explain your work. https://federation.edu.au/current-students/learning-and-study/online-help-with/guides-to-your-assessments https://federation.edu.au/current-students/learning-and-study/online-help-with/guides-to-your-assessments CRICOS Provider No. 00103D 1400 Assig 2, 2020-05 7 Marking Criteria/Rubric Task Mark 1 Pseudo-code for all Python scripts 10 2 Final Python code (Exceptions 2 marks), annotated with author details and with comments throughout the code (2 marks), consistent with pseudo-code 10 3 Tests to check that Python code is working correctly 10 4 Case 1 - Fibonacci numbers using example Excel sheet 5 5 Case 2 - Fibonacci numbers using your Python script – bar chart (10) & table (5) 15 6 Case 3 - Lengths of Rivers using your Python script – bar chart (10) & table (5) 15 7 Discussion (including 4 Questions in Step 6) 15 8 Report: Abstract, Title Page, Table of Contents (including Figures & Tables), Introduction, Method, Results, Discussion (including the 4 Questions in Step 6 of problem solving), Acknowledgements & Statement of Authorship, References 20 TOTAL 100 Final Grade /20 Feedback Ongoing feedback will be given in lectures and labs/tutes online classes and in arranged meeting. Feedback will also be given in Moodle. Plagiarism Plagiarism is the presentation of the expressed thought or work of another person as though it is one's own without properly acknowledging that person. You must not allow
Answered Same DayJun 01, 2021ITECH1400

Answer To: ITECH1400 Foundations of Programming Logarithms, Benford’s Law and Fraudulent Data Overview In this...

Abr Writing answered on Jun 04 2021
123 Votes
law.py
from collections import Counter
from math import log10
import pandas as pd
import matplotlib.pyplot as plt
# Function for calculating countuencies of first digits in a list of numbers
def get_frequencies(array):
numbers = '123456789'
temp = []
for elem in array:
if str(elem)[0] in numbers:
temp.append(int(str(elem)[0]))
counts = dict(Counter(temp))
count = []
for i in range(1, 10):
if i in counts:
count.append(counts[i])
else:
count.append(0)
return count
# Function for fibonacci series
def get_fibonacci_series(n):
if n < 1:
return []
if n == 1:
return [1]
if n == 2:
return [1, 1]
n_minus_1 = get_fibonacci_series(n-1)
return [n_minus_1[0]+n_minus_1[1]]+n_minus_1
# # Case 2 – Fibonacci numbers & Benford’s law using Python
actual = get_frequencies(get_fibonacci_series(24))
actual_percentage = [i/sum(actual)*100 for i in actual]
bernard_percentage = [log10(1+1/i)*100 for i in range(1,10)]
plt.plot(range(1,10), actual_percentage)
plt.plot(range(1,10), bernard_percentage)
plt.legend(['Actual Percentage',
'Benford\'s Law predicted %'],
loc='upper right')
plt.xlabel('Leading Number')
plt.ylabel('Percentage')
plt.title('Fibonacci series up to the 24th term')
plt.show()
actual = get_frequencies(get_fibonacci_series(50))
actual_percentage = [i/sum(actual)*100 for i in actual]
plt.plot(range(1,10), actual_percentage)
plt.plot(range(1,10), bernard_percentage)
plt.legend(['Actual Percentage',
'Benford\'s Law predicted %'],
loc='upper right')
plt.xlabel('Leading Number')
plt.ylabel('Percentage')
plt.title('Fibonacci series up to the 50th term')
plt.show()
# # Case 3 – river_length of Rivers in the World
rivers = pd.read_excel('Rivers.xlsx')
river_length = rivers.loc[:,'Length (miles)']
actual = get_frequencies(river_length)
actual_percentage = [i/sum(actual)*100 for i in actual]
plt.plot(range(1,10), actual_percentage)
plt.plot(range(1,10), bernard_percentage)
plt.legend(['Actual Percentage',
'Benford\'s Law predicted %'],
loc='upper right')
plt.xlabel('Leading Number')
plt.ylabel('Percentage')
plt.title('Length of Rivers')
plt.show()
Benford's Law.xlsx
Benford's Law
        Value        Leading Digit Value                Leading Digit        Count        Actual Percentage        Benford's Law predicted %        Variation per digit                        Leading Digit        Count        Actual Percentage        Benford's Law predicted %        Variation per digit
        1        1                1        7        29.17%        30.10%        -0.0094                        1        16        32.00%        30.10%        0.0190
        1        1                2        5        20.83%        17.61%        0.0322                        2        9        18.00%        17.61%        0.0039
        2        2                3        3        12.50%        12.49%        0.0001                        3        6        12.00%        12.49%        -0.0049
        3        3                4        2        8.33%        9.69%        -0.0136                        4        4        8.00%        9.69%        -0.0169
        5        5                5        2        8.33%        7.92%        0.0042                        5        4        8.00%        7.92%        0.0008
        8        8                6        2        8.33%        6.69%        0.0164                        6        3        6.00%        6.69%        -0.0069
        13        1                7        0        0.00%        5.80%        -0.0580                        7        3        6.00%        5.80%        0.0020
        21        2                8        2        8.33%        5.12%        0.0322                        8        3        6.00%        5.12%        0.0088
        34        3                9        1        4.17%        4.58%        -0.0041                        9        2        4.00%        4.58%        -0.0058
        55        5                TOTAL        24                                                TOTAL        50
        89        8
        144        1                ChiTest comparison as %                99.999983%                                        ChiTest comparison as...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here