Other model metrics

Marketing Analytics: Predicting Customer Churn in Python

Mark Peterson

Director of Data Science, Infoblox

Probability thresholds

  • Every prediction your classifier makes has an associated probability
  • Default probability threshold in scikit-learn: 50%

 

  • What if we vary this threshold?
Marketing Analytics: Predicting Customer Churn in Python

ROC curve part 1

Marketing Analytics: Predicting Customer Churn in Python

ROC curve part 2

Marketing Analytics: Predicting Customer Churn in Python

ROC curve part 3

Marketing Analytics: Predicting Customer Churn in Python

ROC curve part 4

Marketing Analytics: Predicting Customer Churn in Python

ROC curve part 5

Marketing Analytics: Predicting Customer Churn in Python

ROC curve part 6

Marketing Analytics: Predicting Customer Churn in Python

ROC curve part 7

Marketing Analytics: Predicting Customer Churn in Python

ROC curve part 8

Marketing Analytics: Predicting Customer Churn in Python

Generating probabilities in sklearn

logreg.predict_proba(X_test)[:,1]
array([[0.80188981, 0.19811019],
       [0.96484075, 0.03515925],
       [0.9182671 , 0.0817329 ],
       ...,
y_pred_prob = logreg.predict_proba(X_test)[:,1]
Marketing Analytics: Predicting Customer Churn in Python

ROC curve in sklearn

from sklearn.metrics import roc_curve

fpr, tpr, thresholds = roc_curve(y_test, y_pred_prob)
import matplotlib.pyplot as plt

plt.plot(fpr, tpr)

plt.xlabel("False Positive Rate")

plt.ylabel("True Positive Rate")

plt.plot([0, 1], [0, 1], "k--")

plt.show()
Marketing Analytics: Predicting Customer Churn in Python

Area under the curve

from sklearn.metrics import roc_auc_score

auc = roc_auc_score(y_test, y_pred)
Marketing Analytics: Predicting Customer Churn in Python

Let's practice!

Marketing Analytics: Predicting Customer Churn in Python

Preparing Video For Download...