Skip to content

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.

ColumnDescription
SessionIDunique session ID
Administrativenumber of pages visited related to the customer account
Administrative_Durationtotal amount of time spent (in seconds) on administrative pages
Informationalnumber of pages visited related to the website and the company
Informational_Durationtotal amount of time spent (in seconds) on informational pages
ProductRelatednumber of pages visited related to available products
ProductRelated_Durationtotal amount of time spent (in seconds) on product-related pages
BounceRatesaverage bounce rate of pages visited by the customer
ExitRatesaverage exit rate of pages visited by the customer
PageValuesaverage page value of pages visited by the customer
SpecialDaycloseness of the site visiting time to a specific special day
Weekendindicator whether the session is on a weekend
Monthmonth of the session date
CustomerTypecustomer type
Purchaseclass 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]

correlations = []
for i in range(len(duration_cols)):
    for j in range(i+1, len(duration_cols)):
        col1 = duration_cols[i]
        col2 = duration_cols[j]
        corr_value = return_df[col1].corr(return_df[col2])
        correlations.append( ( (col1, col2), corr_value ) )
strongest_pair = max(correlations, key= lambda x: abs(x[1]))

top_correlation = {
    "pair" : strongest_pair[0],
    "correlation": strongest_pair[1]
}
top_correlation

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

from scipy.stats import binom
prob_at_least_100_sales = 1 -  binom.cdf(99, 500, improved_rate)
print(prob_at_least_100_sales)
#binomial probability distribution chart

n=500
k = np.arange(0,n+1)
plt.bar(k, binom.pmf(k, n, improved_rate))