데이터 리샘플링으로 탐지 성공률 높이기

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 (합성 소수 클래스 오버샘플링)

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...