Machine Learning for Marketing in Python
Karolis Urbonas
Head of Analytics & Science, Amazon
# Customer by product/service matrix
wholesale.head()
wholesale.agg(['mean','std']).round(0)
Fresh Milk Grocery Frozen Detergents_Paper Delicassen
mean 12000.0 5796.0 7951.0 3072.0 2881.0 1525.0
std 12647.0 7380.0 9503.0 4855.0 4768.0 2820.0
# Get the statistics averages = wholesale.mean() st_dev = wholesale.std() x_names = wholesale.columns x_ix = np.arange(wholesale.shape[1])
# Plot the data import matplotlib.pyplot as plt plt.bar(x_ix-0.2, averages, color='grey', label='Average', width=0.4) plt.bar(x_ix+0.2, st_dev, color='orange', label='Standard Deviation', width=0.4) plt.xticks(x_ix, x_names, rotation=90) plt.legend() plt.show()
import seaborn as sns
sns.pairplot(wholesale, diag_kind='kde')
plt.show()
Machine Learning for Marketing in Python