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()
# Start your code here!
# Use as many cells as you like
purchase_nov_dec = shopping_data[shopping_data['Month'].isin(['Nov', 'Dec'])]
rates = purchase_nov_dec.groupby(['CustomerType'])['Purchase']\
                    .value_counts(normalize=True)

purchase_rates = {customer: value for (customer, purchase), value in rates.items() if purchase == 1}

matrix_corr = purchase_nov_dec[['Administrative_Duration', 'Informational_Duration', 'ProductRelated_Duration']].corr()
pairs = []
for i, col1 in enumerate(matrix_corr.columns):
    for j, col2 in enumerate(matrix_corr.columns):
        if i < j:  # Evitar duplicados y la diagonal
            corr = matrix_corr.loc[col1, col2].round(3)
            pairs.append({
                "pair": (col1, col2),
                "correlation": corr
            })

top_correlation = max(pairs, key=lambda x: abs(x["correlation"]))

new_rate = purchase_rates['Returning_Customer'] * 1.15

prob_at_least_100_sales = 1 - stats.binom.cdf(100, 500, new_rate)