性能评估

Python 中的欺诈检测

Charlotte Werger

Data Scientist

准确率并非一切

做欺诈检测时,不要只看准确率

Python 中的欺诈检测

假阳性、假阴性与实际捕获的欺诈

Python 中的欺诈检测

精确率-召回率权衡

Python 中的欺诈检测

获取性能指标

# Import the packages
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import average_precision_score

# Calculate average precision and the PR curve average_precision = average_precision_score(y_test, predicted)
# Obtain precision and recall precision, recall, _ = precision_recall_curve(y_test, predicted)
Python 中的欺诈检测

精确率-召回率曲线

Python 中的欺诈检测

用 ROC 曲线比较算法

# Obtain model probabilities
probs = model.predict_proba(X_test)

# Print ROC_AUC score using probabilities print(metrics.roc_auc_score(y_test, probs[:, 1]))
0.9338879319822626
Python 中的欺诈检测
from sklearn.metrics import classification_report, confusion_matrix

# Obtain predictions predicted = model.predict(X_test)
# Print classification report using predictions print(classification_report(y_test, predicted))
  precision    recall  f1-score   support

        0.0       0.99      1.00      1.00      2099
        1.0       0.96      0.80      0.87        91

avg / total       0.99      0.99      0.99      2190
# Print confusion matrix using predictions
print(confusion_matrix(y_test, predicted))
[[2096    3]
 [  18   73]]
Python 中的欺诈检测

开始练习吧!

Python 中的欺诈检测

Preparing Video For Download...