Machine Learning for Marketing in 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)
.coef_
method on fitted Logistic Regression instancelogreg.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. ]])
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