2015-06-07 09:47:50 +08:00
{
" cells " : [
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ##Customer Churn## \n " ,
" \n " ,
2015-06-14 18:34:33 +08:00
" Credits: Forked from [growth-workshop](https://github.com/aprial/growth-workshop) by [aprial](https://github.com/aprial), as featured on the [yhat blog](http://blog.yhathq.com/posts/predicting-customer-churn-with-sklearn.html) "
2015-06-07 09:47:50 +08:00
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" \n " ,
" \" Churn Rate \" is a business term describing the rate at which customers leave or cease paying for a product or service. It ' s a critical figure in many businesses, as it ' s often the case that acquiring new customers is a lot more costly than retaining existing ones (in some cases, 5 to 20 times more expensive). \n " ,
" \n " ,
" Understanding what keeps customers engaged, therefore, is incredibly valuable, as it is a logical foundation from which to develop retention strategies and roll out operational practices aimed to keep customers from walking out the door. Consequently, there ' s growing interest among companies to develop better churn-detection techniques, leading many to look to data mining and machine learning for new and creative approaches. \n " ,
" \n " ,
" Predicting churn is particularly important for businesses w/ subscription models such as cell phone, cable, or merchant credit card processing plans. But modeling churn has wide reaching applications in many domains. For example, casinos have used predictive models to predict ideal room conditions for keeping patrons at the blackjack table and when to reward unlucky gamblers with front row seats to Celine Dion. Similarly, airlines may offer first class upgrades to complaining customers. The list goes on. "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" Wait, don ' t go! \n " ,
" \n " ,
" So what are some of ops strategies that companies employ to prevent churn? Well, reducing churn, it turns out, often requires non-trivial resources. Specialized retention teams are common in many industries and exist expressly to call down lists of at-risk customers to plead for their continued business. \n " ,
" \n " ,
" ![](http://blog.yhathq.com/static/img/netflix.png) \n " ,
" \n " ,
" Organizing and running such teams is tough. From an ops perspective, cross-geographic teams must be well organized and trained to respond to a huge spectrum of customer complaints. Customers must be accurately targeted based on churn-risk, and retention treatments must be well-conceived and correspond reasonably to match expected customer value to ensure the economics make sense. Spending $1,000 on someone who wasn ' t about to leave can get expensive pretty quickly. \n " ,
" \n " ,
" Within this frame of mind, efficiently dealing with turnover is an exercise of distinguishing who is likely to churn from who is not using the data at our disposal. The remainder of this post will explore a simple case study to show how Python and its scientific libraries can be used to predict churn and how you might deploy such a solution within operations to guide a retention team. \n " ,
" \n " ,
" ##The Dataset## \n " ,
" \n " ,
" The data set we ' ll be using is a longstanding telecom customer data set. \n " ,
" \n " ,
" The data is straightforward. Each row represents a subscribing telephone customer. Each column contains customer attributes such as phone number, call minutes used during different times of day, charges incurred for services, lifetime account duration, and whether or not the customer is still a customer. "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 1 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" from __future__ import division \n " ,
" import pandas as pd \n " ,
" import numpy as np \n " ,
" import matplotlib.pyplot as plt \n " ,
" import json \n " ,
" \n " ,
" from sklearn.cross_validation import KFold \n " ,
" from sklearn.preprocessing import StandardScaler \n " ,
" from sklearn.cross_validation import train_test_split \n " ,
" from sklearn.svm import SVC \n " ,
" from sklearn.ensemble import RandomForestClassifier as RF \n " ,
" % matplotlib inline \n "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 2 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" Column names: \n " ,
" [ ' State ' , ' Account Length ' , ' Area Code ' , ' Phone ' , \" Int ' l Plan \" , ' VMail Plan ' , ' VMail Message ' , ' Day Mins ' , ' Day Calls ' , ' Day Charge ' , ' Eve Mins ' , ' Eve Calls ' , ' Eve Charge ' , ' Night Mins ' , ' Night Calls ' , ' Night Charge ' , ' Intl Mins ' , ' Intl Calls ' , ' Intl Charge ' , ' CustServ Calls ' , ' Churn? ' ] \n " ,
" \n " ,
" Sample data: \n "
]
} ,
{
" data " : {
" text/html " : [
" <div style= \" max-height:1000px;max-width:1500px;overflow:auto; \" > \n " ,
" <table border= \" 1 \" class= \" dataframe \" > \n " ,
" <thead> \n " ,
" <tr style= \" text-align: right; \" > \n " ,
" <th></th> \n " ,
" <th>State</th> \n " ,
" <th>Account Length</th> \n " ,
" <th>Area Code</th> \n " ,
" <th>Phone</th> \n " ,
" <th>Int ' l Plan</th> \n " ,
" <th>VMail Plan</th> \n " ,
" <th>Night Charge</th> \n " ,
" <th>Intl Mins</th> \n " ,
" <th>Intl Calls</th> \n " ,
" <th>Intl Charge</th> \n " ,
" <th>CustServ Calls</th> \n " ,
" <th>Churn?</th> \n " ,
" </tr> \n " ,
" </thead> \n " ,
" <tbody> \n " ,
" <tr> \n " ,
" <th>0</th> \n " ,
" <td> KS</td> \n " ,
" <td> 128</td> \n " ,
" <td> 415</td> \n " ,
" <td> 382-4657</td> \n " ,
" <td> no</td> \n " ,
" <td> yes</td> \n " ,
" <td> 11.01</td> \n " ,
" <td> 10.0</td> \n " ,
" <td> 3</td> \n " ,
" <td> 2.70</td> \n " ,
" <td> 1</td> \n " ,
" <td> False.</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>1</th> \n " ,
" <td> OH</td> \n " ,
" <td> 107</td> \n " ,
" <td> 415</td> \n " ,
" <td> 371-7191</td> \n " ,
" <td> no</td> \n " ,
" <td> yes</td> \n " ,
" <td> 11.45</td> \n " ,
" <td> 13.7</td> \n " ,
" <td> 3</td> \n " ,
" <td> 3.70</td> \n " ,
" <td> 1</td> \n " ,
" <td> False.</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>2</th> \n " ,
" <td> NJ</td> \n " ,
" <td> 137</td> \n " ,
" <td> 415</td> \n " ,
" <td> 358-1921</td> \n " ,
" <td> no</td> \n " ,
" <td> no</td> \n " ,
" <td> 7.32</td> \n " ,
" <td> 12.2</td> \n " ,
" <td> 5</td> \n " ,
" <td> 3.29</td> \n " ,
" <td> 0</td> \n " ,
" <td> False.</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>3</th> \n " ,
" <td> OH</td> \n " ,
" <td> 84</td> \n " ,
" <td> 408</td> \n " ,
" <td> 375-9999</td> \n " ,
" <td> yes</td> \n " ,
" <td> no</td> \n " ,
" <td> 8.86</td> \n " ,
" <td> 6.6</td> \n " ,
" <td> 7</td> \n " ,
" <td> 1.78</td> \n " ,
" <td> 2</td> \n " ,
" <td> False.</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>4</th> \n " ,
" <td> OK</td> \n " ,
" <td> 75</td> \n " ,
" <td> 415</td> \n " ,
" <td> 330-6626</td> \n " ,
" <td> yes</td> \n " ,
" <td> no</td> \n " ,
" <td> 8.41</td> \n " ,
" <td> 10.1</td> \n " ,
" <td> 3</td> \n " ,
" <td> 2.73</td> \n " ,
" <td> 3</td> \n " ,
" <td> False.</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>5</th> \n " ,
" <td> AL</td> \n " ,
" <td> 118</td> \n " ,
" <td> 510</td> \n " ,
" <td> 391-8027</td> \n " ,
" <td> yes</td> \n " ,
" <td> no</td> \n " ,
" <td> 9.18</td> \n " ,
" <td> 6.3</td> \n " ,
" <td> 6</td> \n " ,
" <td> 1.70</td> \n " ,
" <td> 0</td> \n " ,
" <td> False.</td> \n " ,
" </tr> \n " ,
" </tbody> \n " ,
" </table> \n " ,
" </div> "
] ,
" text/plain " : [
" State Account Length Area Code Phone Int ' l Plan VMail Plan \\ \n " ,
" 0 KS 128 415 382-4657 no yes \n " ,
" 1 OH 107 415 371-7191 no yes \n " ,
" 2 NJ 137 415 358-1921 no no \n " ,
" 3 OH 84 408 375-9999 yes no \n " ,
" 4 OK 75 415 330-6626 yes no \n " ,
" 5 AL 118 510 391-8027 yes no \n " ,
" \n " ,
" Night Charge Intl Mins Intl Calls Intl Charge CustServ Calls Churn? \n " ,
" 0 11.01 10.0 3 2.70 1 False. \n " ,
" 1 11.45 13.7 3 3.70 1 False. \n " ,
" 2 7.32 12.2 5 3.29 0 False. \n " ,
" 3 8.86 6.6 7 1.78 2 False. \n " ,
" 4 8.41 10.1 3 2.73 3 False. \n " ,
" 5 9.18 6.3 6 1.70 0 False. "
]
} ,
" execution_count " : 2 ,
" metadata " : { } ,
" output_type " : " execute_result "
}
] ,
" source " : [
" churn_df = pd.read_csv( ' ../data/churn.csv ' ) \n " ,
" col_names = churn_df.columns.tolist() \n " ,
" \n " ,
" print \" Column names: \" \n " ,
" print col_names \n " ,
" \n " ,
" to_show = col_names[:6] + col_names[-6:] \n " ,
" \n " ,
" print \" \\ nSample data: \" \n " ,
" churn_df[to_show].head(6) \n " ,
" "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" We ' ll be keeping the statistical model pretty simple for this example so the feature space is almost unchanged from what you see above. The following code simply drops irrelevant columns and converts strings to boolean values (since models don ' t handle \" yes \" and \" no \" very well). The rest of the numeric columns are left untouched. "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 3 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" # Isolate target data \n " ,
" churn_result = churn_df[ ' Churn? ' ] \n " ,
" y = np.where(churn_result == ' True. ' ,1,0) \n "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 4 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" # We don ' t need these columns \n " ,
" to_drop = [ ' State ' , ' Area Code ' , ' Phone ' , ' Churn? ' ] \n " ,
" churn_feat_space = churn_df.drop(to_drop,axis=1) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 5 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" # ' yes ' / ' no ' has to be converted to boolean values \n " ,
" # NumPy converts these from boolean to 1. and 0. later \n " ,
" yes_no_cols = [ \" Int ' l Plan \" , \" VMail Plan \" ] \n " ,
" churn_feat_space[yes_no_cols] = churn_feat_space[yes_no_cols] == ' yes ' "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 6 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" Index([u ' Account Length ' , u ' Int ' l Plan ' , u ' VMail Plan ' , u ' VMail Message ' , u ' Day Mins ' , u ' Day Calls ' , u ' Day Charge ' , u ' Eve Mins ' , u ' Eve Calls ' , u ' Eve Charge ' , u ' Night Mins ' , u ' Night Calls ' , u ' Night Charge ' , u ' Intl Mins ' , u ' Intl Calls ' , u ' Intl Charge ' , u ' CustServ Calls ' ], dtype= ' object ' ) \n "
]
}
] ,
" source " : [
" # Pull out features for future use \n " ,
" features = churn_feat_space.columns \n " ,
" print features "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 7 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" Feature space holds 3333 observations and 17 features \n " ,
" Unique target labels: [0 1] \n "
]
}
] ,
" source " : [
" X = churn_feat_space.as_matrix().astype(np.float) \n " ,
" \n " ,
" # This is important \n " ,
" scaler = StandardScaler() \n " ,
" X = scaler.fit_transform(X) \n " ,
" print \" Feature space holds %d observations and %d features \" % X .shape \n " ,
" print \" Unique target labels: \" , np.unique(y) \n " ,
" "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" One slight side note. Many predictors care about the relative size of different features even though those scales might be arbitrary. For instance: the number of points a basketball team scores per game will naturally be a couple orders of magnitude larger than their win percentage. But this doesn ' t mean that the latter is 100 times less signifigant. `StandardScaler` fixes this by normalizing each feature to a range of around 1.0 to -1.0 thereby preventing models from misbehaving. Well, at least for that reason. \n " ,
" \n " ,
" Great, I now have a feature space `X` and a set of target values `y`. On to the predictions! \n " ,
" \n " ,
" ##How good is your model?## \n " ,
" \n " ,
" Express, test, cycle. A machine learning pipeline should be anything but static. There are always new features to design, new data to use, new classifiers to consider each with unique parameters to tune. And for every change it ' s critical to be able to ask, \" Is the new version better than the last? \" So how do I do that? \n " ,
" \n " ,
" As a good start, cross validation will be used throught this example. Cross validation attempts to avoid overfitting (training on and predicting the same datapoint) while still producing a prediction for each observation dataset. This is accomplished by systematically hiding different subsets of the data while training a set of models. After training, each model predicts on the subset that had been hidden to it, emulating multiple train-test splits. When done correctly, every observation will have a ' fair ' corresponding prediction. \n " ,
" \n " ,
" Here ' s what that looks like using `scikit-learn` libraries. "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 8 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" from sklearn.cross_validation import KFold \n " ,
" \n " ,
" def run_cv(X,y,clf_class,**kwargs): \n " ,
" # Construct a kfolds object \n " ,
" kf = KFold(len(y),n_folds=3,shuffle=True) \n " ,
" y_pred = y.copy() \n " ,
" \n " ,
" # Iterate through folds \n " ,
" for train_index, test_index in kf: \n " ,
" X_train, X_test = X[train_index], X[test_index] \n " ,
" y_train = y[train_index] \n " ,
" # Initialize a classifier with key word arguments \n " ,
" clf = clf_class(**kwargs) \n " ,
" clf.fit(X_train,y_train) \n " ,
" y_pred[test_index] = clf.predict(X_test) \n " ,
" return y_pred "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" Let ' s compare three fairly unique algorithms support vector machines, random forest, and k-nearest-neighbors. Nothing fancy here, just passing each to cross validation and determining how often the classifier predicted the correct class. "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 9 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" Logistic Regression: \n " ,
" 0.862 \n " ,
" Gradient Boosting Classifier \n " ,
" 0.950 \n " ,
" Support vector machines: \n " ,
" 0.912 \n " ,
" Random forest: \n " ,
" 0.935 \n " ,
" K-nearest-neighbors: \n " ,
" 0.893 \n "
]
}
] ,
" source " : [
" from sklearn.svm import SVC \n " ,
" from sklearn.ensemble import RandomForestClassifier as RF \n " ,
" from sklearn.neighbors import KNeighborsClassifier as KNN \n " ,
" from sklearn.linear_model import LogisticRegression as LR \n " ,
" from sklearn.ensemble import GradientBoostingClassifier as GBC \n " ,
" from sklearn.metrics import average_precision_score \n " ,
" \n " ,
" def accuracy(y_true,y_pred): \n " ,
" # NumPy interpretes True and False as 1. and 0. \n " ,
" return np.mean(y_true == y_pred) \n " ,
" \n " ,
" print \" Logistic Regression: \" \n " ,
" print \" %.3f \" % a ccuracy(y, run_cv(X,y,LR)) \n " ,
" print \" Gradient Boosting Classifier \" \n " ,
" print \" %.3f \" % a ccuracy(y, run_cv(X,y,GBC)) \n " ,
" print \" Support vector machines: \" \n " ,
" print \" %.3f \" % a ccuracy(y, run_cv(X,y,SVC)) \n " ,
" print \" Random forest: \" \n " ,
" print \" %.3f \" % a ccuracy(y, run_cv(X,y,RF)) \n " ,
" print \" K-nearest-neighbors: \" \n " ,
" print \" %.3f \" % a ccuracy(y, run_cv(X,y,KNN)) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" \n " ,
" Random forest won, right? \n " ,
" \n " ,
" ##Precision and recall## \n " ,
" \n " ,
" Measurements aren ' t golden formulas which always spit out high numbers for good models and low numbers for bad ones. Inherently they convey something sentiment about a model ' s performance, and it ' s the job of the human designer to determine each number ' s validity. The problem with accuracy is that outcomes aren ' t necessarily equal. If my classifier predicted a customer would churn and they didn ' t, that ' s not the best but it ' s forgivable. However, if my classifier predicted a customer would return, I didn ' t act, and then they churned... that ' s really bad. \n " ,
" \n " ,
" We ' ll be using another built in `scikit-learn` function to construction a confusion matrix. A confusion matrix is a way of visualizing predictions made by a classifier and is just a table showing the distribution of predictions for a specific class. The x-axis indicates the true class of each observation (if a customer churned or not) while the y-axis corresponds to the class predicted by the model (if my classifier said a customer would churned or not). \n " ,
" \n " ,
" ## Confusion matrix and confusion tables: \n " ,
" The columns represent the actual class and the rows represent the predicted class. Lets evaluate performance: \n " ,
" \n " ,
" | | condition True | condition false| \n " ,
" |------|----------------|---------------| \n " ,
" |prediction true|True Positive|False positive| \n " ,
" |Prediction False|False Negative|True Negative| \n " ,
" \n " ,
" Sensitivity, Recall or True Positive Rate quantify the models ability to predict our positive classes. \n " ,
" \n " ,
" $$TPR = \\ frac { TP} { TP + FN}$$ \n " ,
" \n " ,
" Specificity or True Negative Rate quantify the models ability to predict our Negative classes. \n " ,
" \n " ,
" $$TNR = \\ frac { TN} { FP + TN}$$ \n " ,
" \n " ,
" ### Example: \n " ,
" \n " ,
" | | Spam | Ham| \n " ,
" |------|----------------|---------------| \n " ,
" |prediction Spam|100|50| \n " ,
" |Prediction Ham|75|900| \n " ,
" \n " ,
" $$TPR = \\ frac {100} { 100 + 75} = 57.14 \\ % Sensitive $$ \n " ,
" \n " ,
" $$TNR = \\ frac { 900} { 50 + 900} = 94.73 \\ % Specific $$ \n " ,
" \n "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 10 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" [[2821 29] \n " ,
" [ 244 239]] \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAAAUAAAAEWCAYAAAAXR05AAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz \n AAALEgAACxIB0t1+/AAAHjhJREFUeJzt3Xm4HFW57/HvLxOjTCIKYhIUooCoBE2OcqMR0YvDFTmK \n iMoRZy8qXsUJjwNxwqPn4CznyqCgggOCgoLA4RANqAQhUYYwSpgTAYEwCBl4zx9rdVLpdO/u3bv2 \n 7q5dv8/z1LO7q1avWruq++1Vq6rrVURgZlZHE/rdADOzfnEANLPacgA0s9pyADSz2nIANLPacgA0 \n s9rqawCUtImksyTdJ+knI6jnTZLOLbNt/SJpjqRrenzt0yUtlrRC0vvKbpuND5KWSnpJm2U9v/+q \n qKsAKOmNkv4k6QFJd0g6W9LeJaz/dcB2wDYRcVCvlUTEjyLif5fQnlEl6TFJTx2qTEQsiIhn9LiK \n jwIXRMQWEfGtHutYS9JWkk6UdGcOqtdK+thI6x0N+UO9T5tlT5a0qtW2l3SGpK+MYL0d9+kw65ue \n 67y8af62klZKuqmE1USeNlwwsvdf5XQMgJI+BHw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ZaTgd1HhdaeRhmBOIb0fTyedxGi3vubPxFBta7ThMtJ74FuknvX1pBMhkK4OOZq0Le8kHZof2VxZ \n vzUG981KJelQ0gmZOW2WX0g64XXimDbMrMC/BbZ+Gq2hCLOuOACOMkn7SbpG0vUa0J+RjZJuDrEH \n +vBD6WeAyyVd0e+22OjwIfAoyj8vuxbYlzSGdilwcEQs6WvDrCuS5pCuTDg5Ivbod3usfO4Bjq5Z \n pJ9fLc0D7j8mXYJhFRARC0hnvW2ccgAcXU9m/Yteb2PDa+PMrE8cAEeXxxfMBpgD4Oi6nXTNWcNT \n WP+XGGbWRw6Ao+tPwC7
" text/plain " : [
" <matplotlib.figure.Figure at 0x10c33edd0> "
]
} ,
" metadata " : { } ,
" output_type " : " display_data "
} ,
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" [[2814 36] \n " ,
" [ 147 336]] \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAAAT0AAAEWCAYAAAAU8EBoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz \n AAALEgAACxIB0t1+/AAAG4lJREFUeJzt3Xm4HHWd7/H3JyFh3xclCARHGBYZJVyTUS4aHHCAxyuD \n 4iB4GVG8OBdRRp1xwPEq4SKOoxdFcfQZNgEFYRAUFAZQORJBDGAiW5BFwp4gEBL2LHzvH/XrnErT \n fU6f6j7pqq7P63nqoZZfV337VOXLr5auryICM7O6mNDvAMzM1iQnPTOrFSc9M6sVJz0zqxUnPTOr \n FSc9M6uV2iQ9SetKukLSM5Iu6mI9H5R0dS9j6xdJe0u6u+Bn/1zSPElLJR3b69jGk6Spkl6RVJvj \n 34aVbqdLOlzSLZKelfSYpCsl7dWDVR8CbAVsFhGHFl1JRPwgIv66B/GMq/SP+vUjtYmI2RGxc8FN \n fBb4RURsFBGnF1zHKpJOlLQ87fdnJN0kae9u19tvkhZIeiF9r2fT/yReuwa3PyTpqDW1vSooVdKT \n 9Gng68DJZAlqW+DbwHt6sPrt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FnAwMC3XvLkMw+vIeniPpvH8/EdHitnX9MyssHU7HJqla3ZnAXdFxDeaFu8L \n zI+Ix3LzLgc+IGmypB2AHYE5EbEQWCppRlrnEcCPGYF7emZWWBcJZC/gfwK35R5LOSHddT2U4RsY \n AETEXZIuJivBsAI4JoZf+34M8D2y/HrlSHduu4zZzOqu6M/QIuLXtDnTjIiWdUki4hTglBbzbwV2 \n 73TbTnpmVlgVE0gVYzazkvALB8ysVqqYQKoYs5mVhHt6ZlYrVXzLipOemRXmnp6Z1UoVE0gVYzaz \n kpjUaQZZMa5hjImTnpk
" text/plain " : [
" <matplotlib.figure.Figure at 0x10c60b1d0> "
]
} ,
" metadata " : { } ,
" output_type " : " display_data "
} ,
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" [[2813 37] \n " ,
" [ 317 166]] \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAAAT0AAAEWCAYAAAAU8EBoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz \n AAALEgAACxIB0t1+/AAAHg5JREFUeJzt3Xm4HFW57/HvL4EAAoZZASFBARmciNdE5aDRgwper8hR \n BFRExYPnII6co4BeJQ54nXAenqOAgAJ6UDAoKIhsCahEJNEgQcRjgACJypAwCJne+8danVQ63b17 \n V/dOd3X/Ps9Tz+6qWlW1uqv63atqVderiMDMbFhM6HUFzMw2Jgc9MxsqDnpmNlQc9MxsqDjomdlQ \n cdAzs6FSmaAnaQtJl0p6QNJ3O1jP6yX9tJt16xVJB0m6peSyT5U0X9JySSd2u27WPkkPSpraZtk1 \n kp7cZN6bJM3pZt0GUdeDnqTXSboh78i7JV0m6cAurPo1wE7AdhFxZNmVRMR3IuJlXajPuGp1cNdE \n xJyI2KfkJt4HXBURj4+IL5dcx1qSTpN0XmF8V0m3SPp8g7Lfyu/vOYVpe0pa02k9uqmdICJpZn4v \n X6mbfq2kY9vZTkRsHRGLOqiqjUFXg56k9wKfAz5GClC7AV8BXtmF1U8Bbo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xveXFp/75SZ9YiDXvf5 \n eoFZH3PQ67672PCO+kY/JTKzHnDQ674bgL0kTZU0ifS7Tve+mfUJB70uyz+rOpH0aKebge+657Y6 \n JF1A+rnW3pLulOSbggeMb1kxs6Hilp6ZDRUHPTMbKg56ZjZUHPTMbKg46JnZUNkYOUGbkuSuY7Me \n iYiOngo+1u9vp9vrlp4GPUjPCR9UI6RUWYNq1kDvPRjsPTirK2tpN1v7B7uyte7oedAzs+oaS/KQ \n fuGgZ2alVTGAuCNjHE3
" text/plain " : [
" <matplotlib.figure.Figure at 0x10c7c6e10> "
]
} ,
" metadata " : { } ,
" output_type " : " display_data "
} ,
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" [[2820 30] \n " ,
" [ 124 359]] \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAAAUkAAAEWCAYAAADrUmWKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz \n AAALEgAACxIB0t1+/AAAHrBJREFUeJzt3Xm8HGWd7/HPNyGBsBh2JSoJKhkiw1VQiYrRMIOKXB0G \n xUFQFMWLc3G7gsOIG8RxGUbFXcaFKKCAiKKgIDBKJKgY0ERZgoAaCJBElhB2svC7fzxP59TpdFf3 \n 6dOnT9c53/frVa9TXetTS//OU09V108RgZmZNTZhtAtgZtbPHCTNzEo4SJqZlXCQNDMr4SBpZlbC \n QdLMrMSoBklJUyRdJOl+Sd8bxnLeKOnSbpZttEiaI+mmDuf9O0lLJD0g6V3dLttIkXSypLNy/66S \n HpSk0S5XrwznmHdh3UdJWjiCy79Y0pGFzx+XdLekuyQ9vQrHuq0gKekISdfmDborb/h+XVj/ocDO \n wPYRcVinC4mI70bEK7tQnhEl6QlJzyibJiIWRsQeHa7iBODnEfGkiPhyh8sYRNLuks6V9DdJayTd \n LOmLkp7ajeVnGx/WjYjbI2Kb6MIDvJIWSDq6ZPyMfEwezN1KSV+RtNlw192iXIPOg2Ee83bW90pJ \n V+Z/nn/L++U1I7W+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LPc3Uy6w/4og5uuXglcn7fpc8AbIuJxUnvi90mB80bS \n zdFmFaWy4zXUY90TtRsSZlZBkmaRbupNjvH1vHHP+LfbZhUj6RBJm+f26VOACx0gR46DZJ+QdKCk \n myTdIunfR7s81j5J8yWtknRdj1Z5DKld81ZS+19927d1kS+3+0Bu8P4TcACp3ega4PCIWDqqBbO2 \n 5LvCD5EeiG/3zrtVhGu
" text/plain " : [
" <matplotlib.figure.Figure at 0x10d212790> "
]
} ,
" metadata " : { } ,
" output_type " : " display_data "
} ,
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" [[2769 81] \n " ,
" [ 381 102]] \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAAAT0AAAEWCAYAAAAU8EBoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz \n AAALEgAACxIB0t1+/AAAHS9JREFUeJzt3Xm8JHV57/HPd1Z2EBEFBAZlUdCrLM6oXHBU4AVGJbhj \n QkDxYkSEq0QF48IYl4i5GGPEXGURVFCDu0KAKEdBhVFkZBEckG3YRvZBBmZ98sfv13NqerrP6VPd \n Pd116vt+vep1uquqf/V0V52nf7V0PYoIzMzqYsqgAzAzW5+c9MysVpz0zKxWnPTMrFac9MysVpz0 \n zKxWKpf0JG0o6UeSHpH0rS7a+RtJF/cytkGRtJ+km0q+djdJCyQtkXRcr2PrhU7fn6STJX1ljOmT \n Zp1PhKTHJM0adBzDQv26Tk/SW4H3AbsBjwELgE9GxC+7bPcI4DjgJRGxuutAh5yk1cDOEXFrn9o/ \n E3gkIk7sUXunAM+OiCN60V4XccwCbgWmdbudSPoqcDiwHFgBXAMcHxE3dBelDUJfenqS3gd8DvgE \n sDWwPfBF4LU9aH5HYGEdEl6B2k6QpnXZ9o7AH8q8UNLUFqOH7Wr3tp/dBATwmYjYFNgWuBM4uwft \n rqUH69I6ERE9HYDNST27148xz0zgX4G78/A5YEaeNhe4i9RLXAzcAxyVp80DlpG+cR8D3g6cAnyt \n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XnEyqdb2KdGfoS/L4 \n vUkV6zYALoyIE8aKZeBJz8yqa3r5l64A3hsRC3Ihq6slXRoRb27MIOlfSPU+kLQ76ddNu5Nu4PHf \n knbJVfW+RCpjOl/ShZIOjoi2N6D1MT0zK21ah0OziLgvIhbkx38BbqRQcjVXy3sTqYgYpNuznR8R \n K3Ltj1uAObn856YRMT/
" text/plain " : [
" <matplotlib.figure.Figure at 0x10d38d7d0> "
]
} ,
" metadata " : { } ,
" output_type " : " display_data "
}
] ,
" source " : [
" from sklearn.metrics import confusion_matrix \n " ,
" from sklearn.metrics import precision_score \n " ,
" from sklearn.metrics import recall_score \n " ,
" \n " ,
" def draw_confusion_matrices(confusion_matricies,class_names): \n " ,
" class_names = class_names.tolist() \n " ,
" for cm in confusion_matrices: \n " ,
" classifier, cm = cm[0], cm[1] \n " ,
" print(cm) \n " ,
" \n " ,
" fig = plt.figure() \n " ,
" ax = fig.add_subplot(111) \n " ,
" cax = ax.matshow(cm) \n " ,
" plt.title( ' Confusion matrix for %s ' % c lassifier) \n " ,
" fig.colorbar(cax) \n " ,
" ax.set_xticklabels([ ' ' ] + class_names) \n " ,
" ax.set_yticklabels([ ' ' ] + class_names) \n " ,
" plt.xlabel( ' Predicted ' ) \n " ,
" plt.ylabel( ' True ' ) \n " ,
" plt.show() \n " ,
" \n " ,
" y = np.array(y) \n " ,
" class_names = np.unique(y) \n " ,
" \n " ,
" confusion_matrices = [ \n " ,
" ( \" Support Vector Machines \" , confusion_matrix(y,run_cv(X,y,SVC)) ), \n " ,
" ( \" Random Forest \" , confusion_matrix(y,run_cv(X,y,RF)) ), \n " ,
" ( \" K-Nearest-Neighbors \" , confusion_matrix(y,run_cv(X,y,KNN)) ), \n " ,
" ( \" Gradient Boosting Classifier \" , confusion_matrix(y,run_cv(X,y,GBC)) ), \n " ,
" ( \" Logisitic Regression \" , confusion_matrix(y,run_cv(X,y,LR)) ) \n " ,
" ] \n " ,
" \n " ,
" # Pyplot code not included to reduce clutter \n " ,
" # from churn_display import draw_confusion_matrices \n " ,
" % matplotlib inline \n " ,
" \n " ,
" draw_confusion_matrices(confusion_matrices,class_names) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" An important question to ask might be, When an individual churns, how often does my classifier predict that correctly? This measurement is called \" recall \" and a quick look at these diagrams can demonstrate that random forest is clearly best for this criteria. Out of all the churn cases (outcome \" 1 \" ) random forest correctly retrieved 330 out of 482. This translates to a churn \" recall \" of about 68 % (330/482≈2/3), far better than support vector machines (≈50 % ) or k-nearest-neighbors (≈35 % ). \n " ,
" \n " ,
" Another question of importance is \" precision \" or, When a classifier predicts an individual will churn, how often does that individual actually churn? The differences in sematic are small from the previous question, but it makes quite a different. Random forest again out preforms the other two at about 93 % precision (330 out of 356) with support vector machines a little behind at about 87 % (235 out of 269). K-nearest-neighbors lags at about 80 % . \n " ,
" \n " ,
" While, just like accuracy, precision and recall still rank random forest above SVC and KNN, this won ' t always be true. When different measurements do return a different pecking order, understanding the values and tradeoffs of each rating should effect how you proceed. "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## ROC Plots & AUC \n " ,
" \n " ,
" Another important metric to consider is ROC plots. We ' ll cover the majority of these concepts in lecture, but if you ' re itching for more, one of the best resources out there is this [academic paper](https://cours.etsmtl.ca/sys828/REFS/A1/Fawcett_PRL2006.pdf). \n " ,
" \n " ,
" Simply put, the area under the curve (AUC) of a receiver operating characteristic (ROC) curve is a way to reduce ROC performance to a single value representing expected performance. \n " ,
" To explain with a little more detail, a ROC curve plots the true positives (sensitivity) vs. false positives (1 − specificity), for a binary classifier system as its discrimination threshold is varied. Since a random method describes a horizontal curve through the unit interval, it has an AUC of .5. Minimally, classifiers should perform better than this, and the extent to which they score higher than one another (meaning the area under the ROC curve is larger), they have better expected performance. "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 11 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" Support vector machines: \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAAAX4AAAEZCAYAAACQK04eAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz \n AAALEgAACxIB0t1+/AAAIABJREFUeJzsnXeYJFX1v9/P5gyzIGHJGZYcJCihF1QWJJgQUUEMNIqg \n P1EkKLArSRQRBcEtQRAUlChBEBWmSV+CZEQQlrTksIFdWDbO+f1xbs/W9HT39Mx0mOm57/PUM91V \n t6pOdfecunXuuecjMyMSiUQiA4dBjTYgEolEIvUlOv5IJBIZYETHH4lEIgOM6PgjkUhkgBEdfyQS \n iQwwouOPRCKRAUZ0/JGKkfQfSbs22o5GI+kCST+u8zkvkXRKPc9ZKyR9SdKtPdw3/gargGIef/9E \n 0ovASsBS4H3gn8C3zWxuI+1qNiQdCnzdzHZpsB0XAy+b2UkNtmMKsJ6ZHVyHc12CX/OJtT7XQCP2 \n +PsvBuxjZmOBLYHNgbr2QquBpCED8dyNRNLggXjuyDKi428CzOxN4B/Apvl1knaU9H+SZkt6VNJu \n qW3jJV0s6VVJsyRdl9q2T2g/W9I9kjZPbXtR0u6SJkiaL6kltW1rSW/n/7ElfU3Sf8Px/y5pzVTb \n NklHSHoW+F+xa5K0n6Qngx2tkjYusOO4sH2WpN9LGt6Na/ihpMeBeZIGh2NNlzQ3HPNToe0mwAXA \n TpLmSZoV1reHXSRlJL0i6WhJb0p6LTwl5M+3gqQbJb0r6QFJp0q6q9R3KWnn1Pc2Q9Ihqc3jJd0U \n 7LxP0rqp/X4V2r8r6UFJO6e2TZF0taTLJL0LfEXShyXdG87zmqRzJQ1N7bOppH9KminpDUnHS9oT \n OB44MHwej4S2y0m6KBznFUmnSBoUth0avoOzJb0DTAnr7grbJemX4bN7V9Lj4dxZ4IvAD8O5rk99 \n f3uE14MlnZD67h6UtHqpzzaSwszi0g8X4AVgj/B6deBx4KTwfjXgHWByeP+x8H6F8P5vwBXAcsAQ \n YJewfmvgTeDDgIBD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1Jlc/o08ZoHBvGaBwa9ueZSneYY6olEIpEBRnT8kUgkMsAYCI4/12gDGkCu \n 0QY0gFyjDWgAuUYb0AByjTagAeSqfcCapnNK+j0+3f6tgqJN6Ta/xkvMzsfL5T5SpI31NMYfiUQi \n A5VSvrPWPf6LgcmlNkraG68OuAGQxSsGRiKRSKSG1NTxm9ldwOwyTfbDC1dhZvcDy0tauZY2RSKR \n yECn0TH+1egsUhE1MyORyIAjX+q6HvSFPP7Ci42TtSKRSNMSHPwGwEdw4ZmNGDJkU9ZddxXlco/l \n 260/f/6YFZYsGXb/uHHbWSazsJo2NNrxv0pHRaLV6aiy1I6kKam3OTPL1c6sSCTS7EjMwgXqO3Ls \n eBhZLkJdwFL42RmwdEnnTUfjQgVpngQ2LWy4ZAkjn3+dv02yXRkMM/eeybu7vstKf1mJsQ+yAOta \n +AdAUoZl2gml29W6SJuktYEbi2X1hMHdI81sb0k7AueY2Y5F2sWsnkgkUlUkzIo4VE2VMYUd8N54 \n flkPl/hcw8wWdTyONALaFhQ/zVgze6+wPfDoruy6xZ3LPXYWe+65CltuOZzNN19j2uuvHwFcggvp \n HJ7NZl/r3TUW95017fFLugLYDVhR0svAybgwM2Y2zcxulrS3pOnA+0AUp4hEIj2iZA++E+/CZ1aD \n Hd9HJ2EM7tRgNnATHQXjAfgfvEWBXrUBx8KCn8Gv6RyqXlx4jFZaZxrWIjR70l95EPgJcNPn3n77 \n JeBWXB3tsmw2W7Neeb8oyxx7/JFIpCukhQYjOvWwfZvOAD4KrIMnleT9yc5mdk+R9n8ARjJ+/Ous \n uOIrrLrqS2y22atPX3fd3Rv/6U8b9sbO1kk8M6mV/DE+CexkmcyBSZKMA8b0tpefppTvjI4/EonU \n nXzv/HruZhxFguNd8Az
" text/plain " : [
" <matplotlib.figure.Figure at 0x10c334610> "
]
} ,
" metadata " : { } ,
" output_type " : " display_data "
} ,
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" Random forests: \n "
]
} ,
{
" data " : {
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Yxm \n 5+pxOByOYYZT/A6HwzHMGA6KP5pvAfJANN8C5IFovgXIA9F8C5AHovkWIA9Es91hTsM5ReT3mOn2 \n 25OSNnnb/C8mxWwjJl3uv1O00f76+B0Oh2O4kk535trivwU4Od1OEfkYJjvgHCCMyRjocDgcjhyS \n U8Wvqk8Bu3posgiTuApVfQEYKSLjcymTw+FwDHfy7eOfTPciFa5mpsPhGNbYNN7pUonvNYMhjj/Z \n /+Qmazkcjn2WqERlNM+WFbBjP4jPuJk3Pvw0W46pDcQm7qaptDZeFwLkCwd9RX938p8l2vra+Nse \n v3p7rx33gXwr/s10rUg0ha5VljoQkSWe1aiqRnMnlsPhcPRMVKISpLa4nDen+2maCToVZPIOmqa9 \n S82MKhrGbaexYjuNJTuoLzhMDpWP+xf5kGLZ7juS5qJ26kqV1bFmnt0eNaV0AL/fz6LTFnHECQey \n 8e0NK1gtbZnKJCKVdNZOSN8u10naRGQG8FCqqB47uHuhqn5MRN4PXK+q70/RzkX1OByOnBCVqADF \n RWycUMymmT5apgFTFN9EJTAuTmCMEqxoJ1S+m1jJFhqKqmgIjWCs/0DmEWCP+miMx3ytsT1FEr/L \n 94T/j3tuCyafp+TIE7XsvK+37A5saWvwrwrQuslH8551vLNmFU+vb6Sl7cVTDz61+pQTTvm23+9f \n IyKLw+Hwlr25tnS6M6cWv4jcCRwHjBGRjcCVmMLMqOoyVX1ERD4mIquABsAVp3A4HP0iocCF1tEl \n rJ4eZM80ITYNmKj4xlsFPipOqDxOQUmMgqIYxYXCiIAQo40gTUxoD9DY6qOpSWltbiPW8i/eDvyK \n R8dXsyfYSmvHuGhwxoc
" text/plain " : [
" <matplotlib.figure.Figure at 0x10d933b50> "
]
} ,
" metadata " : { } ,
" output_type " : " display_data "
} ,
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" K-nearest-neighbors: \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAAAX4AAAEZCAYAAACQK04eAAAABHNCSVQ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8Vi6am0pDvD3eN/DDihpZ0ichImOuBowIOJGGixWCyWMBJW \n xa+qnwIlrRQ5FRO4ClX9GkgTkb7hlMlisVh6OpG28Q9kzyQVNmemxWKxhJHO4Mff1P5kJ2tZLJYe \n gYjEYUKbj3PFJE9N6dX71CRX7NDzJ17tyohP7JUs8a5vK3/o+/Cnd2xrq669IdKKfwu7ZyQaxO5Z \n lnYiIvOCVn2q6gufWBaLxdL+yG/XxA4sLjtubPWG8/qVbZstyGB1+rqB+nJ27CinMiqGrLEEYidW \n ypbFhavq18Y1m7+h2fpF3OzKndByuXAHaRORYcCbzXn1OIO7v1HVk0TkYOA+VT24mXLWq8disXR6 \n RGQ4rujxZI49OsEV746uKx1TX1mYdMUsb2BAaWpU//xY0kugJLOaitQdevW6X0mUy+VPjIkt9NdX \n +EYeNGXN3LPP/llsbOxKl8vl8Xg8W/dTnmZ1Z1h7/CLyHHAk0FtENgO3YhIzo6rzVfUdETlJRNYC \n lYBNTmGxWDo1IpLIlCm1/Oj5Yb0qOGZExY7j+9ftmDaksr5fUmxGfEVdMRQuozromIQt2XUJ8YEN \n DUkr302J+u7JH+VVLCNPGy6Rn0U3Zpbzer2nYLKOXQs85fF4wtYr7xJhmW2P32KxRAIZetAJxPc5 \n I7a+fmZsVdHwhvK8pOqqQtevJ/2TWSWj6JcP5SnVBBK3ozF5gb9ue9hfUl9UnUjNygZ/bfaGAB9X \n mJSUuaraNFH9bni93hQ
" text/plain " : [
" <matplotlib.figure.Figure at 0x10d93b510> "
]
} ,
" metadata " : { } ,
" output_type " : " display_data "
} ,
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" Gradient Boosting Classifier: \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAAAX4AAAEZCAYAAACQK04eAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz \n AAALEgAACxIB0t1+/AAAIABJREFUeJzsnXmYHFX1v99PNkJWEvYlLLIjEED2dRJQWQIIKAgKgkIj \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UqYiamZFIJFJBukIef278KU7WikQiJaPGxp8B+1fbjmL0+eKL3l99770NZaZZL73U68tZs3os \n WrCABR9/3HPBRx/1/GLGjB5fOeqouf2/8pWsFgHLQc8BoK8++eTKv77iijnltKfajv8DmisSrUZz \n laXFSBqTettoZo2VMysSiXQjdgTGh6XzOGH4XTRpIO8dCXP+1XL76gkM+kYw8CH24t9cxQ+Y8tal \n fPbZMy2a/+TsVQdswnpYT2PantOYtfMsVvj7Cgx85gezuaJ14R8ASQ0s0U4o3K7SRdokrQnclS+r \n JwzuHmdme0raFjjfzLbN0y5m9UQi3QA1No4Ezi37cZuatPL06SvIrEV4etqgQUN+ec01//h/1103 \n Md++U6DPyzDQcqILa8K8dT2bsBljYKN/wbpfhI6xgT6BZX4Cj57iojSh3ejRYxg7djh89yVYP/c4 \n Z8GNv3BBeIBdgdsxO0/SicBXcbWx14HXruXa+77P95ceN27chsCVwKRTppwyauYZMzvk9wr5zkqn \n c94A7IKLPk8BRuPCzJjZuNDmQjzzZy5whJk9V6rxkUika6HGxr/hql23lvO4P7r77jUzd911+aQV \n V7wpd9u0+fP7fPDcc/23WrRo6t6uONeMr8Me/4Ktc9ePYAQ701Ih8n7u5ymearH+MA7jCFrq58xn \n PgtZ2GJ9X/rSm94t1ud
" text/plain " : [
" <matplotlib.figure.Figure at 0x10dcfa1d0> "
]
} ,
" metadata " : { } ,
" output_type " : " display_data "
}
] ,
" source " : [
" from sklearn.metrics import roc_curve, auc \n " ,
" from scipy import interp \n " ,
" \n " ,
" def plot_roc(X, y, clf_class, **kwargs): \n " ,
" kf = KFold(len(y), n_folds=5, shuffle=True) \n " ,
" y_prob = np.zeros((len(y),2)) \n " ,
" mean_tpr = 0.0 \n " ,
" mean_fpr = np.linspace(0, 1, 100) \n " ,
" all_tpr = [] \n " ,
" for i, (train_index, test_index) in enumerate(kf): \n " ,
" X_train, X_test = X[train_index], X[test_index] \n " ,
" y_train = y[train_index] \n " ,
" clf = clf_class(**kwargs) \n " ,
" clf.fit(X_train,y_train) \n " ,
" # Predict probabilities, not classes \n " ,
" y_prob[test_index] = clf.predict_proba(X_test) \n " ,
" fpr, tpr, thresholds = roc_curve(y[test_index], y_prob[test_index, 1]) \n " ,
" mean_tpr += interp(mean_fpr, fpr, tpr) \n " ,
" mean_tpr[0] = 0.0 \n " ,
" roc_auc = auc(fpr, tpr) \n " ,
" plt.plot(fpr, tpr, lw=1, label= ' ROC fold %d (area = %0.2f ) ' % (i, roc_auc)) \n " ,
" mean_tpr /= len(kf) \n " ,
" mean_tpr[-1] = 1.0 \n " ,
" mean_auc = auc(mean_fpr, mean_tpr) \n " ,
" plt.plot(mean_fpr, mean_tpr, ' k-- ' ,label= ' Mean ROC (area = %0.2f ) ' % mean_auc, lw=2) \n " ,
" \n " ,
" plt.plot([0, 1], [0, 1], ' -- ' , color=(0.6, 0.6, 0.6), label= ' Random ' ) \n " ,
" plt.xlim([-0.05, 1.05]) \n " ,
" plt.ylim([-0.05, 1.05]) \n " ,
" plt.xlabel( ' False Positive Rate ' ) \n " ,
" plt.ylabel( ' True Positive Rate ' ) \n " ,
" plt.title( ' Receiver operating characteristic ' ) \n " ,
" plt.legend(loc= \" lower right \" ) \n " ,
" plt.show() \n " ,
" \n " ,
" \n " ,
" print \" Support vector machines: \" \n " ,
" plot_roc(X,y,SVC,probability=True) \n " ,
" \n " ,
" print \" Random forests: \" \n " ,
" plot_roc(X,y,RF,n_estimators=18) \n " ,
" \n " ,
" print \" K-nearest-neighbors: \" \n " ,
" plot_roc(X,y,KNN) \n " ,
" \n " ,
" print \" Gradient Boosting Classifier: \" \n " ,
" plot_roc(X,y,GBC) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## Feature Importance \n " ,
" \n " ,
" Now that we understand the accuracy of each individual model for our particular dataset, let ' s dive a little deeper to get a better understanding of what features or behaviours are causing our customers to churn. In the next section, we will be using a `RandomForestClassifer` to build an ensemble of decision trees to predict whether a customer will churn or not churn. One of the first steps in building a decision tree to calculating the _information gain_ associated with splitting on a particular feature. (More on this later.) \n " ,
" \n " ,
" Let ' s look at the Top 10 features in our dataset that contribute to customer churn: "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 12 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" Feature ranking: \n " ,
" 1. Account Length (0.188157) \n " ,
" 2. Int ' l Plan (0.102871) \n " ,
" 3. VMail Plan (0.096911) \n " ,
" 4. VMail Message (0.071246) \n " ,
" 5. Day Mins (0.062060) \n " ,
" 6. Day Calls (0.032456) \n " ,
" 7. Day Charge (0.030478) \n " ,
" 8. Eve Mins (0.026043) \n " ,
" 9. Eve Calls (0.025411) \n " ,
" 10. Eve Charge (0.021707) \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAAAXYAAAEKCAYAAAAGvn7fAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz \n AAALEgAACxIB0t1+/AAAGKFJREFUeJzt3X20XXV95/H3JzeE5wIqDxqCcVFadVWnOE5Mi8BVU1ag \n amy7OshoLeJYZjqpTH1YDF1dEuta49K1HLF16qQQuyxiM5WCjWuwBIrXsnwIyRQES8IQJEOejOEp \n IJQxkM/8sXfI5nLvebgP59zzO5/XWmfds8/+7fPd++Tmc3/3t397X9kmIiLKMa/fOxARETMrwR4R \n UZgEe0REYRLsERGFSbBHRBQmwR4RUZgEewwVSVdIurrf+xExm5R57NEpSduAk4Dn6pcM/ILtH0/z \n PS+xfdu0d3DASFoFnG77d/q9L1GW+f3egRgoBt4+wyFsQFPdWNKI7efat5xbJOX/XsyaDMXEtEk6 \n TtIaSbsk7ZD0SUnz6nWnS7pN0sOS9kr6iqTj6nXXAqcB35D0pKSPShqVtH3c+2+T9Nb6+SpJ10u6 \n VtI+4Hdb1Z9gX1fVdZG0WNIBSRdLekjSI5L+g6R/I+luSY9J+rPGthdL+o6kP5P0uKTNB/erXv8K \n Sevq97lf0r8fV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krZIul/S \n 5ROsf4+kH0i6W9J3JL2+sW5b/fqdku6Y6Z2PiIgXm99qpaQR4AvAMmAnsFHSOtubG81+BJxje5+k \n 5cBfAEvrdQZGbT8687seERETaddjXwJstb3N9n5gLbCi2cD292zvqxc3AKeOew/NyJ5GRERHWvbY \n gYXA9sbyDuBNLdp/ALipsWzgVknPAattXz2lvZxBEqPAaL04CozVz8fs559HRAysdsHuTt9I0luA \n S4CzGi+fZXu3pBOBWyRtsX37FPZzxtThPQYgYfv5kI+IKEK7YN8JLGosL6Lqtb9AfcL0amC57ccO \n vm57d/11r6QbqYZ2XhTsklY1Fsdsj3W4/xERQ0HSKHTWEZU9eadc0nzgPuBtwC7gDuCi5slTSacB \n twHvtf39xutHASO2n5R0NLAe+ITt9eNq2HZfxuHrHnvOAUTEwGmVnS177LaflbQSuBkYAdbY3izp \n 0nr9auDjwAnAFyUB7Le9BDgFuKF+bT5w3fhQj4iImdeyx96THUiPPSKia62yM1eeRkQUJsEeEVGY \n BHtERGES7BERhUmwR0QUJsEeEVGYBHtERGES7BERhUmwR0QUJsEeEVGYBHtERGES7BERhUmwR0QU \n JsEeEVGYBHtERGES7BERhUmwR0QUJsEeEVGYBHtERGES7BERhUmwR0QUJsEeEVGYBHtERGES7BER \n hUmwR0QUJsEeEVGYBHtERGES7BERhUmwR0QUpm2wS1ouaYuk+yVdPsH690j6gaS7JX1H0us73TYi \n ImaebE++UhoB7gOWATuBjcBFtjc32vwKcK/tfZKWA6tsL+1k23p729YMH1dHJGzTl9oREdPRKjvb \n 9diXAFttb7O9H1gLrGg2sP092/vqxQ3AqZ1uGxERM69dsC8EtjeWd9SvTeYDwE1T3DYiImbA/Dbr \n Jx+nGUfSW4BLgLOmsO2qxuKY7bFOt42IGAaSRoHRTtq2C/adwKLG8iKqnvf4gq8HrgaW236sm20B \n bK/qZGcjIoZV3eEdO7gs6crJ2rYbitkEnCFpsaQFwIXAumYDSacBNwDvtb21m20jImLmteyx235W \n 0krgZmAEWGN7s6RL6/WrgY8DJwBflASw3/aSybadxWOJiAjaTHfsyQ5kumNERNemM90xIiIGTII9 \n IqIwCfaIiMIk2CMiCtNuHvvAkDSFs8Duert+neiNiOhUMcEOXVzqWlOX2yTRI2IQZCgmIqIwCfaI \n iMIk2CMiCpNgj4goTII
" text/plain " : [
" <matplotlib.figure.Figure at 0x10d5ceed0> "
]
} ,
" metadata " : { } ,
" output_type " : " display_data "
}
] ,
" source " : [
" train_index,test_index = train_test_split(churn_df.index) \n " ,
" \n " ,
" forest = RF() \n " ,
" forest_fit = forest.fit(X[train_index], y[train_index]) \n " ,
" forest_predictions = forest_fit.predict(X[test_index]) \n " ,
" \n " ,
" importances = forest_fit.feature_importances_[:10] \n " ,
" std = np.std([tree.feature_importances_ for tree in forest.estimators_], \n " ,
" axis=0) \n " ,
" indices = np.argsort(importances)[::-1] \n " ,
" \n " ,
" # Print the feature ranking \n " ,
" print( \" Feature ranking: \" ) \n " ,
" \n " ,
" for f in range(10): \n " ,
" print( \" %d . %s ( %f ) \" % (f + 1, features[f], importances[indices[f]])) \n " ,
" \n " ,
" # Plot the feature importances of the forest \n " ,
" #import pylab as pl \n " ,
" plt.figure() \n " ,
" plt.title( \" Feature importances \" ) \n " ,
" plt.bar(range(10), importances[indices], yerr=std[indices], color= \" r \" , align= \" center \" ) \n " ,
" plt.xticks(range(10), indices) \n " ,
" plt.xlim([-1, 10]) \n " ,
" plt.show() "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## Thinking in Probabilities \n " ,
" \n " ,
" Decision making often favors probability over simple classifications. There ' s plainly more information in statements like \" there ' s a 20 % c hance of rain tomorrow \" and \" about 55 % o f test takers pass the California bar exam \" than just saying \" it shouldn ' t rain tomorrow \" or \" you ' ll probably pass. \" Probability predictions for churn also allow us to gauge a customers expected value, and their expected loss. Who do you want to reach out to first, the client with a 80 % c hurn risk who pays 20,000 annually, or the client who ' s worth 100,000 a year with a 40 % r isk? How much should you spend on each client? \n " ,
" \n " ,
" While I ' m moving a bit away from my expertise, being able to ask that question requires producing predictions a little differently. However, `scikit-learn` makes moving to probabilities easy; my three models have `predict_proba()` built right into their class objects. This is the same cross validation code with only a few lines changed. "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 13 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" def run_prob_cv(X, y, clf_class, roc=False, **kwargs): \n " ,
" kf = KFold(len(y), n_folds=5, shuffle=True) \n " ,
" y_prob = np.zeros((len(y),2)) \n " ,
" for train_index, test_index in kf: \n " ,
" X_train, X_test = X[train_index], X[test_index] \n " ,
" y_train = y[train_index] \n " ,
" clf = clf_class(**kwargs) \n " ,
" clf.fit(X_train,y_train) \n " ,
" # Predict probabilities, not classes \n " ,
" y_prob[test_index] = clf.predict_proba(X_test) \n " ,
" return y_prob "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## How good is good? \n " ,
" \n " ,
" Determining how good a predictor which gives probabilities rather than classes is a bit more difficult. If I predict there ' s a 20 % li kelihood of rain tomorrow I don ' t get to live out all the possible outcomes of the universe. It either rains or it doesn ' t. \n " ,
" \n " ,
" What helps is that the predictors aren ' t making one prediction, they ' re making 3000+. So for every time I predict an event to occur 20 % o f the time I can see how often those events actually happen. Here ' s we ' ll use `pandas` to help me compare the predictions made by random forest against the actual outcomes. "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 14 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" data " : {
" text/plain " : [
" 0.0 1796 \n " ,
" 0.1 681 \n " ,
" 0.2 258 \n " ,
" 0.3 112 \n " ,
" 0.8 94 \n " ,
" 0.9 89 \n " ,
" 0.7 79 \n " ,
" 0.4 74 \n " ,
" 0.5 53 \n " ,
" 0.6 50 \n " ,
" 1.0 47 \n " ,
" dtype: int64 "
]
} ,
" execution_count " : 14 ,
" metadata " : { } ,
" output_type " : " execute_result "
}
] ,
" source " : [
" import warnings \n " ,
" warnings.filterwarnings( ' ignore ' ) \n " ,
" \n " ,
" # Use 10 estimators so predictions are all multiples of 0.1 \n " ,
" pred_prob = run_prob_cv(X, y, RF, n_estimators=10) \n " ,
" pred_churn = pred_prob[:,1] \n " ,
" is_churn = y == 1 \n " ,
" \n " ,
" # Number of times a predicted probability is assigned to an observation \n " ,
" counts = pd.value_counts(pred_churn) \n " ,
" counts[:] "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 15 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" data " : {
" text/html " : [
" <div style= \" max-height:1000px;max-width:1500px;overflow:auto; \" > \n " ,
" <table border= \" 1 \" class= \" dataframe \" > \n " ,
" <thead> \n " ,
" <tr style= \" text-align: right; \" > \n " ,
" <th></th> \n " ,
" <th>pred_prob</th> \n " ,
" <th>count</th> \n " ,
" <th>true_prob</th> \n " ,
" </tr> \n " ,
" </thead> \n " ,
" <tbody> \n " ,
" <tr> \n " ,
" <th>0 </th> \n " ,
" <td> 0.0</td> \n " ,
" <td> 1796</td> \n " ,
" <td> 0.027840</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>1 </th> \n " ,
" <td> 0.1</td> \n " ,
" <td> 681</td> \n " ,
" <td> 0.020558</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>2 </th> \n " ,
" <td> 0.2</td> \n " ,
" <td> 258</td> \n " ,
" <td> 0.081395</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>3 </th> \n " ,
" <td> 0.3</td> \n " ,
" <td> 112</td> \n " ,
" <td> 0.089286</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>4 </th> \n " ,
" <td> 0.4</td> \n " ,
" <td> 74</td> \n " ,
" <td> 0.270270</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>5 </th> \n " ,
" <td> 0.5</td> \n " ,
" <td> 53</td> \n " ,
" <td> 0.622642</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>6 </th> \n " ,
" <td> 0.6</td> \n " ,
" <td> 50</td> \n " ,
" <td> 0.800000</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>7 </th> \n " ,
" <td> 0.7</td> \n " ,
" <td> 79</td> \n " ,
" <td> 0.898734</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>8 </th> \n " ,
" <td> 0.8</td> \n " ,
" <td> 94</td> \n " ,
" <td> 0.957447</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>9 </th> \n " ,
" <td> 0.9</td> \n " ,
" <td> 89</td> \n " ,
" <td> 0.977528</td> \n " ,
" </tr> \n " ,
" <tr> \n " ,
" <th>10</th> \n " ,
" <td> 1.0</td> \n " ,
" <td> 47</td> \n " ,
" <td> 1.000000</td> \n " ,
" </tr> \n " ,
" </tbody> \n " ,
" </table> \n " ,
" </div> "
] ,
" text/plain " : [
" pred_prob count true_prob \n " ,
" 0 0.0 1796 0.027840 \n " ,
" 1 0.1 681 0.020558 \n " ,
" 2 0.2 258 0.081395 \n " ,
" 3 0.3 112 0.089286 \n " ,
" 4 0.4 74 0.270270 \n " ,
" 5 0.5 53 0.622642 \n " ,
" 6 0.6 50 0.800000 \n " ,
" 7 0.7 79 0.898734 \n " ,
" 8 0.8 94 0.957447 \n " ,
" 9 0.9 89 0.977528 \n " ,
" 10 1.0 47 1.000000 "
]
} ,
" execution_count " : 15 ,
" metadata " : { } ,
" output_type " : " execute_result "
}
] ,
" source " : [
" from collections import defaultdict \n " ,
" true_prob = defaultdict(float) \n " ,
" \n " ,
" # calculate true probabilities \n " ,
" for prob in counts.index: \n " ,
" true_prob[prob] = np.mean(is_churn[pred_churn == prob]) \n " ,
" true_prob = pd.Series(true_prob) \n " ,
" \n " ,
" # pandas-fu \n " ,
" counts = pd.concat([counts,true_prob], axis=1).reset_index() \n " ,
" counts.columns = [ ' pred_prob ' , ' count ' , ' true_prob ' ] \n " ,
" counts "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" We can see that random forests predicted that 75 individuals would have a 0.9 proability of churn and in actuality that group had a ~0.97 rate. \n " ,
" \n " ,
" ## Calibration and Descrimination \n " ,
" \n " ,
" Using the `DataFrame` above we can draw a pretty simple graph to help visualize probability measurements. The x axis represents the churn probabilities which random forest assigned to a group of individuals. The y axis is the actual rate of churn within that group, and each point is scaled relative to the size of the group. \n " ,
" \n " ,
" ![](http://blog.yhathq.com/static/img/ggplot.png) \n " ,
" \n " ,
" Calibration is a relatively simple measurement and can be summed up as so: Events predicted to happen 60 % o f the time should happen 60 % o f the time. For all individuals I predict to have a churn risk of between 30 and 40 % , the true churn rate for that group should be about 35 % . For the graph above think of it as, How close are my predictions to the red line? \n " ,
" \n " ,
" Discrimination measures _How far are my predictions away from the green line?_ Why is that important? \n " ,
" \n " ,
" Well, if we assign a churn probability of 15 % to every individual we ' ll have near perfect calibration due to averages, but I ' ll be lacking any real insight. Discrimination gives a model a better score if it ' s able to isolate groups which are further from the base set. \n " ,
" \n " ,
" Equations are replicated from [Yang, Yates, and Smith (1991)](https://www.google.com/search?q=Measures+of+Discrimination+Skill+in+Probabilistic+Judgment&oq=Measures+of+Discrimination+Skill+in+Probabilistic+Judgment) and the code Yhat wrote can be found on GitHub [here](https://github.com/EricChiang/churn/blob/master/churn_measurements.py). "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 17 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" from churn_measurements import calibration, discrimination \n " ,
" from sklearn.metrics import roc_curve, auc \n " ,
" from scipy import interp \n " ,
" from __future__ import division \n " ,
" from operator import idiv \n " ,
" \n " ,
" \n " ,
" \n " ,
" def print_measurements(pred_prob): \n " ,
" churn_prob, is_churn = pred_prob[:,1], y == 1 \n " ,
" print \" %-20s %.4f \" % ( \" Calibration Error \" , calibration(churn_prob, is_churn)) \n " ,
" print \" %-20s %.4f \" % ( \" Discrimination \" , discrimination(churn_prob,is_churn)) \n " ,
" \n " ,
" print \" Note -- Lower calibration is better, higher discrimination is better \" "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 18 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" Support vector machines: \n " ,
" Calibration Error 0.0016 \n " ,
" Discrimination 0.0678 \n " ,
" Note -- Lower calibration is better, higher discrimination is better \n " ,
" Random forests: \n " ,
" Calibration Error 0.0072 \n " ,
" Discrimination 0.0845 \n " ,
" Note -- Lower calibration is better, higher discrimination is better \n " ,
" K-nearest-neighbors: \n " ,
" Calibration Error 0.0023 \n " ,
" Discrimination 0.0443 \n " ,
" Note -- Lower calibration is better, higher discrimination is better \n " ,
" Gradient Boosting Classifier: \n " ,
" Calibration Error 0.0017 \n " ,
" Discrimination 0.0859 \n " ,
" Note -- Lower calibration is better, higher discrimination is better \n " ,
" Random Forest: \n " ,
" Calibration Error 0.0062 \n " ,
" Discrimination 0.0782 \n " ,
" Note -- Lower calibration is better, higher discrimination is better \n "
]
}
] ,
" source " : [
" print \" Support vector machines: \" \n " ,
" print_measurements(run_prob_cv(X,y,SVC,probability=True)) \n " ,
" \n " ,
" print \" Random forests: \" \n " ,
" print_measurements(run_prob_cv(X,y,RF,n_estimators=18)) \n " ,
" \n " ,
" print \" K-nearest-neighbors: \" \n " ,
" print_measurements(run_prob_cv(X,y,KNN)) \n " ,
" \n " ,
" print \" Gradient Boosting Classifier: \" \n " ,
" print_measurements(run_prob_cv(X,y,GBC)) \n " ,
" \n " ,
" print \" Random Forest: \" \n " ,
" print_measurements(run_prob_cv(X,y,RF)) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" Unlike the classification comparisons earlier, random forest isn ' t as clearly the front-runner here. While it ' s good at differentiating between high and low probability churn events, it has trouble assigning an accurate probability estimate to those events. For example the group which random forest predicts to have a 30 % c hurn rate actually had a true churn rate of 14 % . Clearly there ' s more work to be done, but I leave that to you as a challenge. "
]
}
] ,
" metadata " : {
" kernelspec " : {
" display_name " : " Python 2 " ,
" language " : " python " ,
" name " : " python2 "
} ,
" language_info " : {
" codemirror_mode " : {
" name " : " ipython " ,
" version " : 2
} ,
" file_extension " : " .py " ,
" mimetype " : " text/x-python " ,
" name " : " python " ,
" nbconvert_exporter " : " python " ,
" pygments_lexer " : " ipython2 " ,
" version " : " 2.7.10 "
}
} ,
" nbformat " : 4 ,
" nbformat_minor " : 0
}