Identify and interpret churn drivers

Machine Learning for Marketing in Python

Karolis Urbonas

Head of Analytics & Science, Amazon

Plotting decision tree rules

from sklearn import tree
import graphviz

exported = tree.export_graphviz( decision_tree=mytree, out_file=None, feature_names=cols, precision=1, class_names=['Not churn','Churn'], filled = True)
graph = graphviz.Source(exported) display(graph)
Machine Learning for Marketing in Python

Interpreting decision tree chart

Decision tree visualization

Machine Learning for Marketing in Python

Logistic regression coefficients

  • Logistic regression returns beta coefficients
  • Can be interpreted as change in log-odds of churn associated with 1 unit increase in the feature

Logistic Regression Model

Machine Learning for Marketing in Python

Extracting logistic regression coefficients

  • Coefficients can be extracted using .coef_ method on fitted Logistic Regression instance
    logreg.coef_
    
array([[ 0.        ,  0.09784772,  0.        , -0.03935476, -0.82068131,
        -0.41231806, -0.14319622, -0.01746504, -0.41830733,  0.        ,
         0.        ,  0.07138468,  0.        ,  0.        ,  0.        ,
         0.        , -0.41424363, -0.59539021,  0.        ,  0.18846525,
         0.        , -0.90766135,  0.90151342,  0.        ]])
Machine Learning for Marketing in Python

Transforming logistic regression coefficients

  • Log-odds is difficult to interpret
  • Solution - calculate exponent of the coefficients
  • This gives us the change in odds associated with 1 unit increase in the feature
coefficients = pd.concat([pd.DataFrame(train_X.columns),
               pd.DataFrame(np.transpose(logit.coef_))], 
               axis = 1)
coefficients.columns = ['Feature', 'Coefficient']

coefficients['Exp_Coefficient'] = np.exp(coefficients['Coefficient'])
coefficients = coefficients[coefficients['Coefficient']!=0] print(coefficients.sort_values(by=['Coefficient']))
Machine Learning for Marketing in Python

Meaning of transformed coefficients

Logistic Regression Coefficients

Machine Learning for Marketing in Python

Let's practice!

Machine Learning for Marketing in Python

Preparing Video For Download...