找出並解讀流失驅動因素

Python 的行銷機器學習

Karolis Urbonas

Head of Analytics & Science, Amazon

繪製決策樹規則

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)
Python 的行銷機器學習

解讀決策樹圖

決策樹視覺化

Python 的行銷機器學習

邏輯斯迴歸係數

  • 邏輯斯迴歸會回傳 beta 係數
  • 可解讀為特徵增加 1 單位時,流失的「對數勝算」變化

邏輯斯迴歸模型

Python 的行銷機器學習

擷取邏輯斯迴歸係數

  • 可用已擬合的 Logistic Regression 物件的 .coef_ 取出係數
    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.        ]])
Python 的行銷機器學習

轉換邏輯斯迴歸係數

  • 「對數勝算」不易直觀解讀
  • 作法:計算係數的「指數」
  • 可得到特徵增加 1 單位時,「勝算」的變化
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']))
Python 的行銷機器學習

轉換後係數的意義

邏輯斯迴歸係數(指數化)

Python 的行銷機器學習

一起來練習吧!

Python 的行銷機器學習

Preparing Video For Download...