新近性特征

R 中的欺诈检测

Tim Verdonck

Professor Data Science at KU Leuven

认证方式 vs 时间

认证方式与时间

R 中的欺诈检测

较大的时间间隔

较大的时间间隔

R 中的欺诈检测

较小的时间间隔

较小的时间间隔

R 中的欺诈检测

新近性为零

新近性为零

R 中的欺诈检测

异常行为

异常行为

R 中的欺诈检测

定义

  • $recency=exp(-\gamma\cdot t)=e^{-\gamma t}$

    • $t$ = 同类连续两次事件的时间间隔
    • $\gamma$ = 调参项,通常接近 0(如 0.01、0.02、0.05)
    • $0 \leq recency \leq 1$
R 中的欺诈检测

新近性 vs 时间

新近性与时间

R 中的欺诈检测

如何选择参数 $\gamma$?

  • (1) 选择在给定时间 $t$ 后的新近性阈值(如 0.01)
  • (2) 计算 $\gamma=-log(recency)/t$

  • 示例:设定 $\gamma$ 使得 $t$ = 180 天后 recency = 0.01

    gamma <- -log(0.01)/180
    print(gamma)
    
0.02558428
R 中的欺诈检测

R 中的新近性特征(步骤 1)

recency_fun <- function(t, gamma, auth_cd, freq_auth) {

n_t <- length(t) if (freq_auth[n_t] == 0) { recency <- 0 # recency = 0 when frequency = 0
} else { time_diff <- t[1] - max(t[2:n_t][auth_cd[(n_t-1):1] == auth_cd[n_t]]) # time-interval = current time - time of previous transfer with same auth_cd
recency <- exp(-gamma * time_diff) } return(recency)
}
R 中的欺诈检测

R 中的新近性特征(步骤 2)

(1) 选择 $\gamma$ 值

gamma <- -log(0.01)/180 # = 0.0256

(2) 使用 rollapply()、group_by() 与 mutate()

library(dplyr) # needed for group_by() and mutate()
library(zoo) # needed for rollapply()
trans <- trans %>% group_by(account_name) %>%
    mutate(rec_auth = rollapply(timestamp,
                               width = list(0:-length(transfer_id)),
                               partial = TRUE,
                               FUN = recency_fun,
                               gamma, authentication_cd, freq_auth))
R 中的欺诈检测
   account_name timestamp authentication_cd rec_auth fraud_flag
1           Bob     44.25              AU02    0.000          0
2         Alice     54.12              AU03    0.000          0
3           Bob     57.45              AU04    0.000          0
4           Bob     64.29              AU02    0.599          0
5         Alice     64.29              AU03    0.771          0
6           Bob     64.29              AU02    1.000          0
7         Alice     70.25              AU03    0.859          0
8           Bob     70.25              AU02    0.859          0
9         Alice     74.08              AU01    0.000          0
...         ...       ...               ...      ...        ...
37          Bob    407.17              AU02    0.002          0
38        Alice    420.17              AU03    0.717          0
39          Bob    441.34              AU03    0.000          1
40        Alice    443.24              AU04    0.000          1
R 中的欺诈检测

基于时间、频率与新近性的特征

基于时间、频率与新近性的特征

R 中的欺诈检测

让我们开始练习吧!

R 中的欺诈检测

Preparing Video For Download...