データ再サンプリングで検出成功率を高める

Pythonで学ぶ不正検知

Charlotte Werger

Data Scientist

アンダーサンプリング

Pythonで学ぶ不正検知

オーバーサンプリング

Pythonで学ぶ不正検知

Pythonでのオーバーサンプリング

from imblearn.over_sampling import RandomOverSampler

method = RandomOverSampler() X_resampled, y_resampled = method.fit_resample(X, y)
compare_plots(X_resampled, y_resampled, X, y)

Pythonで学ぶ不正検知

SMOTE(Synthetic Minority Oversampling Technique)

1 https://www.kaggle.com/rafjaa/resampling-strategies-for-imbalanced-datasets
Pythonで学ぶ不正検知

どの再サンプリング手法を使うか?

  • ランダムアンダーサンプリング(RUS):データを捨てるが計算効率が高い
  • ランダムオーバーサンプリング(ROS):単純で容易だが重複データで学習
  • SMOTE:より高度で現実的なデータセットだが「擬似」データで学習
Pythonで学ぶ不正検知

再サンプリング手法を使う場面

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression

# Define resampling method and split into train and test method = SMOTE() X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.8, random_state=0)
# Apply resampling to the training data only X_resampled, y_resampled = method.fit_resample(X_train, y_train)
# Continue fitting the model and obtain predictions model = LogisticRegression() model.fit(X_resampled, y_resampled)
# Get your performance metrics predicted = model.predict(X_test) print (classification_report(y_test, predicted))
Pythonで学ぶ不正検知

演習に進みましょう!

Pythonで学ぶ不正検知

Preparing Video For Download...