ランダムアンダーサンプリング

Rで学ぶ不正検知

Bart Baesens

Professor Data Science at KU Leuven

ランダムアンダーサンプリング(RUS)

アンダーサンプリング後のクラス分布バー図

Rで学ぶ不正検知

元データの学習/テスト分割

Rで学ぶ不正検知

ランダムアンダーサンプリング v0

Rで学ぶ不正検知

ランダムアンダーサンプリング v1

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で学ぶ不正検知

アンダーサンプリング後のcreditcardの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で学ぶ不正検知

両方適用後のcreditcardのV2対V1

Rで学ぶ不正検知

演習に進みましょう!

Rで学ぶ不正検知

Preparing Video For Download...