<jupyter_start><jupyter_text>Analyzing Marketing Campaign! How coupon marketing can help shape your business?According to [wikibuy](https://wikibuy.com/blog/coupon-statistics-4c49b386c833), 90% of consumers use coupons and by 2022, digital coupon redemption will reach $91 billionBy studying coupon dataset, we can answers questions such as, **what type of customers are shopping in the business? which coupon delivery method drives more consumers to the business, and how much coupon value to give to customers and maintain profit?**Using IBM dataset, we will help answer those questions Importing the necessary library!<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Load the dataset<jupyter_code>data = pd.read_csv("WA_Fn-UseC_-Marketing-Campaign-Plan_-GroceryS.csv", index_col="storeid")
print("Here is the first five rows and colums of the datset")
data.head()
print('The number of rows is {} and the number of colums is {}'.format(data.shape[0], data.shape[1]))
data.describe()<jupyter_output><empty_output><jupyter_text>The result above allows us to verify that no data is missing. The total number of element in each row and colums is the same by looking at count. To enuser some of the data is not missing, running isnull() will help detect any missing values<jupyter_code>no_missing_cols = set(data.columns[data.isnull().mean() == 0])
print("The number of colums with no missing values are \033[1m:", ', '.join(no_missing_cols))<jupyter_output>The number of colums with no missing values are [1m: AmountSpent, StoreLayout, ShoppingStyle, WhoShoppingFor, week, Vegetarian, CouponValue, CouponSequence, gender, StoreSize, HealthyStore, CarryOver, customerID, CouponUser<jupyter_text>Plot chart and results Using correlation, we can check the relationship between rows and columns in the dataset. in the sample data, we will look into the Pearson correlation. The correlation has a max value of 1 and a min value of -1 in general. if the the value is 1, there is a strong positive correlation. This means that if one variable increases the other increase as well. This applies when the value is -1 but the two values are inversely proportional. Note: The correlation below tells us that there 0.57 correlation between CarryOver and week<jupyter_code>data_corr = data.corr(method="pearson")
data_corr<jupyter_output><empty_output><jupyter_text>Now, let's use the seaborn heatmap to create a visualization for the correlation. The heatmap displays the same values above but add color that can help when identifying object with high and low correlation<jupyter_code>fig = plt.figure(figsize = (8,5))
ax = fig.gca()
sns.heatmap(data_corr, annot=True, fmt="f");<jupyter_output><empty_output><jupyter_text>Visualizing Categorical Data<jupyter_code>fig=plt.figure(figsize=(10, 10), dpi= 80, facecolor='w', edgecolor='k')
plt.subplot(2, 2, 1)
vegeterian_ratio = data.Vegetarian.value_counts()
(vegeterian_ratio/data.shape[0]).plot(kind="barh");
plt.title("Vegeterian vs non vegeterian");

plt.subplot(2, 2, 2)
genre_ratio = data.gender.value_counts()
(genre_ratio/data.shape[0]).plot(kind="bar");
plt.title("Female vs Male");<jupyter_output><empty_output><jupyter_text>We can use visuals to find out what percentage of the customers of the store is **Vegetarian and non Vegetarian**.Notice below that people that identify as non vegetarian constitute more than 80% of the customers. 1. **Vegetarian/non Vegetarian**    This graph can help us to look into why is the number is low in terms of vegetarian participation in the store. The answer     can be related to several things such as Store location. Is the store located in area where people strongly support? another question that should be look into is the vegetarian products that the store offers meets the locals desire?2. **Female/Male**    The second graph below shows the Female to Male ratio. The graph shows that there are more Males shoppers than Females shopper. Again Why? This will lead the store owner to investigate the products that are being sold. Do the products match the neighborhood tastes? Should we offer more discount on Females products to attract a diverse customers?<jupyter_code>fig=plt.figure(figsize=(10, 10), dpi= 80, facecolor='w', edgecolor='k')
plt.subplot(2, 2, 3)
shopping_size = data.WhoShoppingFor.value_counts()
(shopping_size/data.shape[0]).plot(kind="bar");
plt.title("Family Size");

plt.subplot(2, 2, 4)
ShoppingStyle = data.ShoppingStyle.value_counts();
(ShoppingStyle/data.shape[0]).plot(kind="pie");
plt.title("Shopping routine");<jupyter_output><empty_output><jupyter_text>Let's find out the percentage of people shopping in the store in family and alone. We can also look into their shopping frequency.1. **Family Size:** Based on the data, we can see that most people shoppe by themselves as compare to self and spouse. it very interesting to see that the number of people shopping with spouse is greater than the number of people shopping with self and family. Is this due to the fact that most people that are frequent shopper are couple with kids?One approach to increase "Self and Family" would be to have marketing event in certain days where accompanied parents get special discount on specific items. 2. **Shopping Routine:** It is not surprising to see from the pie graph below that most customers shoppe weekly. They buy similar items. This can be used in term of inventory. The store management should be able to predict what items need to be ordered.What is striking is that the number of people shopping for on sale product is low. Perhaps, it will be beneficial to revisit and diversify the items on sale to attract unreached customers.<jupyter_code>fig=plt.figure(figsize=(10, 10), dpi= 80, facecolor='w', edgecolor='k')
plt.subplot(2, 2, 3)
CouponUser = data.CouponUser.value_counts()
(CouponUser/data.shape[0]).plot(kind="barh");
plt.title("Coupon User");

plt.subplot(2, 2, 4)
CouponSequence = data.CouponSequence.value_counts()
(CouponSequence/data.shape[0]).plot(kind="bar");
plt.title("Coupon Sequence or combination");<jupyter_output><empty_output><jupyter_text>1. **Coupon Users:** In this section, we can decided whether to invest in certain types of coupon offers. From the plot above, it is evident that the store is reach significant number of people by mailings coupon offers. We also notice that the number coupon from newspaper is lower. One idea to increase and drive the business through the newspaper medium is to offer greater discounts on the newspaper. Also, adding coupon offers on digital newspaper as compare to just paper would help drive the business. 2. **Coupon types:** This section of the data is rather confusing. from the plot it shows that the sequence from the newspapers is quite high even though the store coupon showed some lower return. By assessing the dataset, we noticed that the sequence of the coupon are mixed. some customers that don't used coupon were still label with certain sequence therefore, a recommendation can not be made.<jupyter_code>fig=plt.figure(figsize=(6, 6), dpi= 80, facecolor='w', edgecolor='k')
CouponValue = data.CouponValue.value_counts();
(CouponValue/data.shape[0]).plot(kind="pie");<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08087431693989071, 'fraction_numerical': 0.012158469945355192, 'mean_word_length': 5.797585886722377, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '292407', 'license': 'MIT', 'n_tokens_mistral': 2127, 'n_tokens_neox': 2005, 'n_words': 920, 'path': 'Analyzing Marking Campaign.ipynb', 'repo_name': 'OuedraogoAbdoul/Marketing-Campaigns', 'size': '7320'}