隨機欠抽樣

R 的詐欺偵測

Bart Baesens

Professor Data Science at KU Leuven

隨機欠抽樣(RUS)

類別長條圖:欠抽樣

R 的詐欺偵測

原始資料:訓練/測試

R 的詐欺偵測

隨機欠抽樣:步驟 0

R 的詐欺偵測

隨機欠抽樣:步驟 1

R 的詐欺偵測

資料集檢視:V2 對 V1

R 的詐欺偵測
table(creditcard$Class)
    0     1 
24108   492
n_fraud <- 492
new_frac_fraud <- 0.50
new_n_total <- n_fraud / new_frac_fraud ## = 492 / 0.50 = 984

library(ROSE) undersampling_result <- ovun.sample(formula = Class ~ ., data = creditcard, method = "under", N = new_n_total, seed = 2018)
undersampled_credit <- undersampling_result$data
prop.table(table(undersampled_credit$Class))
  0   1 
0.5 0.5
R 的詐欺偵測

欠抽樣後的 V2 對 V1

R 的詐欺偵測

兩者都試試!

類別長條圖:兩者皆用

R 的詐欺偵測
n_new <- nrow(creditcard) ## = 24600
fraction_fraud_new <- 0.50

sampling_result <- ovun.sample(formula = Class ~ ., data = creditcard, method = "both", N = n_new, p = fraction_fraud_new, seed = 2018) sampled_credit <- sampling_result$data
prop.table(table(sampled_credit$Class))
        0         1 
0.5039837 0.4960163
R 的詐欺偵測

兩者皆用:結果

R 的詐欺偵測

一起來練習吧!

R 的詐欺偵測

Preparing Video For Download...