合成过采样

R 中的欺诈检测

Sebastiaan Höppner

PhD researcher in Data Science at KU Leuven

使用"SMOTE"进行过采样

• SMOTE:Synthetic Minority Oversampling TEchnique (Chawla 等,2002) • 通过创建合成少数类样本来过采样少数类(= 欺诈)

R 中的欺诈检测
dim(transfer_data)
1000    4
head(transfer_data)
  isFraud    amount   balance     ratio
1   false  528.6840 1529.4732 0.3456641
2   false  184.0193  836.3509 0.2200265
3   false 1885.8024 2984.0684 0.6319568
4   false  732.0286 1248.7217 0.5862224
prop.table(table(transfer_data$isFraud))
 false  true
  0.99  0.01
R 中的欺诈检测

smote_scatterplot_1

R 中的欺诈检测

smote_scatterplot_2

R 中的欺诈检测

SMOTE

选择一个欺诈样本 X(Tim)

smote_zoomin

R 中的欺诈检测

SMOTE - 步骤 1

步骤 1

找到 X(Tim)的 K 个最近欺诈 邻居

例如:K = 4

smote_step1

R 中的欺诈检测

SMOTE - 步骤 2

步骤 2

从 Tim 的最近邻中 随机选一个 例如:X4(Bart)

smote_step2

R 中的欺诈检测

SMOTE - 步骤 3

步骤 3:创建合成样本

合成样本情形 1

R 中的欺诈检测

SMOTE - 步骤 3

步骤 3:创建合成样本

合成样本情形 2

R 中的欺诈检测

SMOTE - 步骤 3

步骤 3:创建合成样本

合成样本情形 3

R 中的欺诈检测

SMOTE - 步骤 3

smote_step3

R 中的欺诈检测

SMOTE - 步骤 4

步骤 4

对每个欺诈样本将步骤 1–3 重复 dup_size 次

例如:dup_size = 10

smote_step3

R 中的欺诈检测
library(smotefamily)
smote_output = SMOTE(X = transfer_data[, -1],
                       target = transfer_data$isFraud,
                       K = 4,
                       dup_size = 10)

oversampled_data = smote_output$data
table(oversampled_data$isFraud)
false  true
  990   110
prop.table(table(oversampled_data$isFraud))
false  true
  0.9   0.1
R 中的欺诈检测

smote_result

R 中的欺诈检测

¡Vamos a practicar!

R 中的欺诈检测

Preparing Video For Download...