通过数据重采样提升检测成功率

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

# 定义重采样方法并划分训练/测试集 method = SMOTE() X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.8, random_state=0)
# 仅对训练集进行重采样 X_resampled, y_resampled = method.fit_resample(X_train, y_train)
# 拟合模型并获取预测 model = LogisticRegression() model.fit(X_resampled, y_resampled)
# 获取性能指标 predicted = model.predict(X_test) print (classification_report(y_test, predicted))
Python 中的欺诈检测

Passons à la pratique !

Python 中的欺诈检测

Preparing Video For Download...