用本福特定律做数字分析

R 中的欺诈检测

Bart Baesens

Professor Data Science at KU Leuven

引言

  • 随机翻开一张报纸的某页,记录所有数字的首位(1,2,...,9)。
  • 这些首位的期望频率是多少?

newspaper

R 中的欺诈检测

引言

  • 随机翻开一张报纸的某页,记录所有数字的首位(1,2,...,9)。
  • 这些首位的期望频率是多少?
  • 直觉猜测约为 1/9 = 11%

barplotrnd

R 中的欺诈检测

引言

  • 随机翻开一张报纸的某页,记录所有数字的首位(1,2,...,9)。
  • 这些首位的期望频率是多少?
  • 直觉猜测约为 1/9
  • 本福特定律: 期望频率
    • 数字 1 $\approx$ 30%
    • 数字 9 $\approx$ 4.6%

barplotbf

R 中的欺诈检测

Newcomb 与 Benford

  • "十个数字并非等频出现,这对经常使用对数表的人是显而易见的:前几页磨损得比最后几页快得多。"(Newcomb,1881)
  • Benford 在 20 个不同数据集中考察了数字的首位。

newben

R 中的欺诈检测

本福特定律:首位

若数据集满足本福特定律的首位规则,则首位 $D_1$ 等于 $d_1$ 的概率近似为: $$P(D_1=d_1)=\log(d_1+1)-\log(d_1)=\log\left(1+\frac{1}{d_1}\right) \qquad d_1=1,\ldots,9$$

  • 例子

    • $P(D_1=1)=\log\left(1+\frac{1}{1}\right)=\log(2)=0.3010300$
    • $P(D_1=2)=\log\left(1+\frac{1}{2}\right)=\log(1.5)=0.1760913$
    • $P(D_1=9)=\log\left(1+\frac{1}{9}\right)=\log(1.111111)=0.04575749$
  • Pinkham 发现本福特定律对尺度变换不变。

R 中的欺诈检测

本福特定律:首位

benlaw <- function(d) log10(1 + 1 / d)
benlaw(1)
0.30103

barplotbf

R 中的欺诈检测

我们生成前 1000 个斐波那契数。

fibnum <- numeric(1000)
fibnum[1] <- fibnum[2] <- 1
for (i in 3:1000) { fibnum[i] <- fibnum[i-1] + fibnum[i-2] } 
head(fibnum)
1 1 2 3 5 8

同时生成2 的前 1000 次幂。

pow2 <- 2^(1:1000)
head(pow2)
2 4 8 16 32 64
R 中的欺诈检测

benford.analysis 包的 `benford` 函数

library(benford.analysis)
bfd.fib <- benford(fibnum,
                   number.of.digits = 1)
plot(bfd.fib)

fibonacci

library(benford.analysis)
bfd.pow2 <- benford(pow2,
                    number.of.digits = 1)
plot(bfd.pow2)

pow2

R 中的欺诈检测

Passons à la pratique !

R 中的欺诈检测

Preparing Video For Download...