Online shopping decisions rely on how consumers engage with online store content. You work for a new startup company that has just launched a new online shopping website. The marketing team asks you, a new data scientist, to review a dataset of online shoppers' purchasing intentions gathered over the last year. Specifically, the team wants you to generate some insights into customer browsing behaviors in November and December, the busiest months for shoppers. You have decided to identify two groups of customers: those with a low purchase rate and returning customers. After identifying these groups, you want to determine the probability that any of these customers will make a purchase in a new marketing campaign to help gauge potential success for next year's sales.
Data description:
You are given an online_shopping_session_data.csv that contains several columns about each shopping session. Each shopping session corresponded to a single user.
| Column | Description |
|---|---|
SessionID | unique session ID |
Administrative | number of pages visited related to the customer account |
Administrative_Duration | total amount of time spent (in seconds) on administrative pages |
Informational | number of pages visited related to the website and the company |
Informational_Duration | total amount of time spent (in seconds) on informational pages |
ProductRelated | number of pages visited related to available products |
ProductRelated_Duration | total amount of time spent (in seconds) on product-related pages |
BounceRates | average bounce rate of pages visited by the customer |
ExitRates | average exit rate of pages visited by the customer |
PageValues | average page value of pages visited by the customer |
SpecialDay | closeness of the site visiting time to a specific special day |
Weekend | indicator whether the session is on a weekend |
Month | month of the session date |
CustomerType | customer type |
Purchase | class label whether the customer make a purchase |
# Import required libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
# Load and view your data
shopping_data = pd.read_csv("online_shopping_session_data.csv")
shopping_data.head()What are the purchase rates for online shopping sessions by customer type for November and December?
#filter Nov and Dec
month_subset = shopping_data[shopping_data['Month'].isin(['Nov','Dec'])]
#total count and purchase count by customer type and find rate
purchase_rates = month_subset.groupby('CustomerType')['Purchase'].mean().sort_values().round(3).to_dict()
print(purchase_rates)What is the strongest correlation in total time spent among page types by returning customers in November and December?
#Nov and Dec, returning customers, corr
return_df = month_subset[month_subset['CustomerType'] == 'Returning_Customer']
duration_cols = [col for col in return_df.columns if 'Duration' in col]
from itertools import combinations
correlations = [
((col1, col2), return_df[col1].corr(return_df[col2]))
for col1, col2 in combinations(duration_cols, 2)
]
strongest_pair = max(correlations, key=lambda x: abs(x[1]))
top_correlation = {
"pair" : strongest_pair[0],
"correlation": strongest_pair[1]
}
top_correlationAmong returning customers in November and December, the strongest correlation in total time spent across page types is observed between Administrative pages and Product-related pages, with a moderate positive correlation of 0.42. This indicates that customers who spend more time completing administrative steps (such as account management, login, orders, returns, etc.) also tend to spend more time browsing product-related content.
A new campaign for the returning customers will boost the purchase rate by 15%. What is the likelihood of achieving at least 100 sales out of 500 online shopping sessions for the returning customers?
return_purchase_rate = list(purchase_rates.items())[0][1]
improved_rate = return_purchase_rate * 1.15
# probability of at least 100 sales out of 500
from scipy.stats import binom
prob_at_least_100_sales = 1 - binom.cdf(99, 500, improved_rate)
print(f"The probability of reaching at least 100 out of 500 is {prob_at_least_100_sales:.2%}.")
#binomial probability distribution chart
n=500
k = np.arange(0,n+1)
plt.bar(k, binom.pmf(k, n, improved_rate))This level of confidence (>90%) suggests that the campaign performance outlook is strong and predictable. The downside risk of falling under 100 sales is relatively low (≈8%), which supports the decision to launch the campaign.
This indicates a high likelihood of reaching the 100-sale target, assuming the projected uplift is accurate.