The main focus of this project is to develop an Online Ad Click Predictor for Deliveroo with a “ClickTraining” dataset of 18,000 observations across 9 variables of consumer click data for an ad campaign and a “ClickPrediction” dataset of 2,000 observations on consumer profiles used to predict click/no click. To help understand click-to-conversion behavior, a series of predictive models are constructed to forecast whether a consumer will click on the ad or not. Furthermore, a series of interactive dashboards are designed to allow managers to explore and utilize these predictions effectively for informed decision-making and campaign optimization.

Dowloading the R packages

We download the R packages that are needed to run the code for this project.

# We download the packages needed for this project.
library(ggplot2)
library(corrplot)
library(dplyr)


First, we set up the working directory and load the data set.

0. Load the data

# Check the current working directory
getwd()
## [1] "E:/OneDrive - CentraleSupelec/eloise/ESSEC/T1/Marketing Analytics/Group Project"
# Update the working directory - windows version
setwd("E:/OneDrive - CentraleSupelec/eloise/ESSEC/T1/Marketing Analytics/Group Project/Topic 2 - Online Ad Click Predictor")

# Update the working directory - iOS version
# setwd("~/OneDrive - CentraleSupelec/eloise/ESSEC/T1/Marketing Analytics/Group Project/Topic 2 - Online Ad Click Predictor")

# Check the updated working directory
getwd()
## [1] "E:/OneDrive - CentraleSupelec/eloise/ESSEC/T1/Marketing Analytics/Group Project/Topic 2 - Online Ad Click Predictor"
# Load the RData
load("DeliveryAdClick.RData")


Next, we will perform an exploratory data analysis before going further analysis. It could be noticed that the “ClickTraining” dataset constains 1 more variable “Click_Conversion” than the “ClickPreduction”. In this step, we will focus mainly on the “ClickTraining” dataset.

1. Exploratory data analysis (EDA)

Introduction to Variables: We first have a look on the meaning of the 9 variables. - Region: Geographic region where the ad was displayed. Indicates the location frequency of the audience.

View the Data Structure

We first view the data structure. We notice that there are 5 Categorical Variables: Region, Carrier, Social_Network, Weekday, and Restaurant_Type. and 4 Numeric Variables: Daytime, Time_On_Previous_Website, Number_of_Previous_Orders, and Clicks_Conversion.

Region, Carrier, Social_Network, Weekday, and Restaurant_Type.

str(ClickTraining)
## 'data.frame':    18000 obs. of  9 variables:
##  $ Region                   : chr  "Alsace and East France" "West France" "Paris" "Paris" ...
##  $ Daytime                  : num  0.223 0.734 0.781 0.311 0.91 ...
##  $ Carrier                  : chr  "SFR" "Bouygues" "SFR" "SFR" ...
##  $ Time_On_Previous_Website : num  8.07 257.57 1427.64 1606.26 480.23 ...
##  $ Weekday                  : Factor w/ 7 levels "Friday","Monday",..: 3 3 7 7 4 3 2 3 3 2 ...
##  $ Social_Network           : chr  "Instagram" "Twitter" "Instagram" "Instagram" ...
##  $ Number_of_Previous_Orders: num  3 3 6 4 2 7 2 6 4 4 ...
##  $ Clicks_Conversion        : int  1 1 1 1 1 1 0 1 1 1 ...
##  $ Restaurant_Type          : chr  "French" "French" "French" "Burger" ...

Show the Descriptive Statistics

Then, we get a summary of the training data to examine statistical details like mean, median, quartiles, and count of each variable.

summary(ClickTraining)
##     Region             Daytime           Carrier         
##  Length:18000       Min.   :0.000121   Length:18000      
##  Class :character   1st Qu.:0.244788   Class :character  
##  Mode  :character   Median :0.492349   Mode  :character  
##                     Mean   :0.495189                     
##                     3rd Qu.:0.740757                     
##                     Max.   :0.999992                     
##                                                          
##  Time_On_Previous_Website      Weekday     Social_Network    
##  Min.   :   5.033         Friday   :2593   Length:18000      
##  1st Qu.: 454.132         Monday   :2695   Class :character  
##  Median : 902.860         Saturday :2522   Mode  :character  
##  Mean   : 902.603         Sunday   :2554                     
##  3rd Qu.:1352.777         Thursday :2517                     
##  Max.   :1799.874         Tuesday  :2599                     
##                           Wednesday:2520                     
##  Number_of_Previous_Orders Clicks_Conversion Restaurant_Type   
##  Min.   : 0.000            Min.   :0.0000    Length:18000      
##  1st Qu.: 2.000            1st Qu.:1.0000    Class :character  
##  Median : 3.000            Median :1.0000    Mode  :character  
##  Mean   : 3.082            Mean   :0.8446                      
##  3rd Qu.: 4.000            3rd Qu.:1.0000                      
##  Max.   :11.000            Max.   :1.0000                      
## 

Visualize Categorical Variables

Now, we visualize the distribution of categorical variables like Region, Carrier, Social_Network, Weekday, and Restaurant_Type.

# Region
ggplot(ClickTraining, aes(x=Region, fill=Region)) + 
    geom_bar() + 
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
    labs(title="Ad Distribution by Region", x="Region", y="Count", fill="Region")

# Carrier
ggplot(ClickTraining, aes(x=Carrier, fill=Carrier)) + 
    geom_bar() + 
    labs(title="Ad Distribution by Carrier", x="Carrier", y="Count", fill="Carrier")

# Social Network
ggplot(ClickTraining, aes(x=Social_Network, fill=Social_Network)) + 
    geom_bar() + 
    labs(title="Ad Distribution by Social Network", x="Social Network", y="Count", fill="Social Network")

# Weekday
# Reorder the "Weekday" variable based on a consecutive order
ClickTraining$Weekday <- factor(ClickTraining$Weekday, levels=c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"))
# Create the ggplot bar chart with the reordered "Weekday" variable
ggplot(ClickTraining, aes(x=Weekday, fill=Weekday)) + 
    geom_bar() + 
    labs(title="Ad Distribution by Weekday", x="Weekday", y="Count", fill="Weekday")

# Restaurant Type
ggplot(ClickTraining, aes(x=Restaurant_Type, fill=Restaurant_Type)) + 
    geom_bar() + 
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
    labs(title="Ad Distribution by Restaurant Type", x="Restaurant Type", y="Count", fill="Restaurant Type")

Interpretaions:

  1. Ad Distribution by Region: The distribution of ads across regions seems fairly uniform, with all regions receiving a significant number of ads. This indicates a wide-reaching ad campaign by Deliveroo across different geographic locations.

  2. Ad Distribution by Carrier: The ads are distributed across four major carriers: Bouygues, Free, Orange, and SFR. The distribution is relatively even among these carriers, with each having a substantial share of the ads. This may reflect a strategic decision to target a broad audience regardless of their network carrier.

  3. Ad Distribution by Social Network: Here we see that Facebook, Instagram, and Twitter are all used for displaying ads, each with a large share, possibly indicating that the strategy is to blanket the social network evenly with ads.

  4. Ad Distribution by Weekday: The ads are displayed throughout the week, with a fairly consistent distribution across days. This suggests that Deliveroo aims to maintain a constant presence throughout the week. There doesn’t appear to be a significant difference between weekdays, which may indicate that the audience’s online behavior does not vary much day-to-day, or that the strategy is to blanket the week evenly with ads.

  5. Ad Distribution by Restaurant Type: Ads are promoting a variety of restaurant types, with “Burger”, “French”, “Groceries”, “Kebab”, and “Sushi” being featured. Each category has a robust ad presence, but “Burger” and “French” types are particularly prominent. This could indicate a higher demand or a strategic emphasis on these types of cuisine. The presence of a “NA” category suggests there are some ads where the restaurant type is not specified or is outside the listed categories.

Visualize Numeric Variables

For numeric variables, we plot histograms or boxplots for numeric variables to understand their distribution and identify any outliers.

# Histogram of Daytime
ggplot(ClickTraining, aes(x=Daytime)) +
  geom_histogram(bins=30, fill="#70C1B3") +
  labs(title="Histogram of Daytime", x="Daytime", y="Count")

# Histogram of Time On Previous Website
ggplot(ClickTraining, aes(x=Time_On_Previous_Website)) +
  geom_histogram(bins=30, fill="#70C1B3") +
  labs(title="Histogram of Time On Previous Website", x="Time on Previous Website", y="Count")

# Histogram of Number of Previous Orders
ggplot(ClickTraining, aes(x=Number_of_Previous_Orders)) +
  geom_histogram(bins=30, fill="#70C1B3") +
  labs(title="Histogram of Number of Previous Orders", x="Number of Previous Orders", y="Count")

# Boxplots
ggplot(ClickTraining, aes(y=Daytime)) + geom_boxplot() + labs(title="Boxplot of Daytime")

ggplot(ClickTraining, aes(y=Time_On_Previous_Website)) + geom_boxplot() + labs(title="Boxplot of Time On Previous Website")

ggplot(ClickTraining, aes(y=Number_of_Previous_Orders)) + geom_boxplot() + labs(title="Boxplot of Number of Previous Orders")

Interpretaions:

  1. Daytime: The histogram shows a relatively uniform distribution of ads across different times of the day, which suggests that the ads are not concentrated in any particular time slot. The flat or almost rectangular shape of the histogram indicates that the ad delivery system is likely aiming for a consistent ad presence throughout the day.

The boxplot for Daytime shows that the median value is around the center of the range (0.5), which corroborates the uniform distribution seen in the histogram. There are no outliers, and the quartiles are evenly spaced, indicating no significant concentration of ad times.

  1. Time On Previous Website: In the histogram of the time spent on the previous website before clicking the ad, the data appears to be evenly distributed across various time intervals

The boxplot also reflects this even distribution. There are no outliers and the quartiles are evenly spaced.

  1. Number of Previous Orders: The histogram for the Number of Previous Orders shows that most users have a low to moderate number of previous orders, with the count decreasing as the number of orders increases. This suggests that new or infrequent users are more common than very frequent users.

The boxplot confirms the presence of a few high-value outliers, indicating that there are some very loyal customers with a high number of previous orders. The box’s length indicates a moderate range of values with most users concentrated in a smaller number of previous orders.

Correlation Analysis

Since Daytime, Time_On_Previous_Website, and Number_of_Previous_Orders are numerical, we can check how they correlate with each other and with the target variable.

# Calculate correlation matrix
cor_matrix <- cor(ClickTraining[,sapply(ClickTraining, is.numeric)])
# View the correlation matrix
cor_matrix
##                                Daytime Time_On_Previous_Website
## Daytime                    1.000000000             0.0017164491
## Time_On_Previous_Website   0.001716449             1.0000000000
## Number_of_Previous_Orders -0.011322253             0.0001879907
## Clicks_Conversion          0.177226256             0.1354347050
##                           Number_of_Previous_Orders Clicks_Conversion
## Daytime                               -0.0113222530        0.17722626
## Time_On_Previous_Website               0.0001879907        0.13543471
## Number_of_Previous_Orders              1.0000000000        0.05588423
## Clicks_Conversion                      0.0558842315        1.00000000
# Plot 
# Create a color ramp
color_ramp <- colorRampPalette(c("#B2BCD8", "white","#70C1B3"))

# Define the number of colors we want in our ramp, 
# which typically should be a larger number to allow for a gradient effect.
num_colors <- 200

# Generate the correlation plot with the custom color scheme
corrplot(cor_matrix, method = "circle", type = "upper", 
         tl.col = "black", tl.srt = 45, 
         title = "Correlation Plot", col=color_ramp(num_colors))
## Warning in ind1:ind2: numerical expression has 2 elements: only the first used

There is no significant correlation between Daytime and both Time_On_Previous_Website and Number_of_Previous_Orders. From the correlation plot, daytime has the highest positive correlation with Clicks_Conversion, while Number_of_Previous_Orders has the lowest positive correlation with Clicks_Conversion.

Clicks Conversion Analysis

Analyze how different variables influence the Clicks_Conversion.

# Clicks Conversion by Weekday
ggplot(ClickTraining, aes(x=Weekday, fill=factor(Clicks_Conversion))) + 
    geom_bar(position="fill") + 
    scale_fill_manual(values=c("0"="#B2BCD8", "1"="#70C1B3")) +
    labs(title="Clicks Conversion by Weekday", x="Weekday", y="Proportion", fill="Clicks Conversion")

# Clicks Conversion by Social Network
ggplot(ClickTraining, aes(x=Social_Network, fill=factor(Clicks_Conversion))) + 
    geom_bar(position="fill") + 
    scale_fill_manual(values=c("0"="#B2BCD8", "1"="#70C1B3")) +
    labs(title="Clicks Conversion by Social Network", x="Social Network", y="Proportion", fill="Clicks Conversion")

# Clicks Conversion by Region
ggplot(ClickTraining, aes(x=Region, fill=factor(Clicks_Conversion))) + 
    geom_bar(position="fill") + 
    scale_fill_manual(values=c("0"="#B2BCD8", "1"="#70C1B3")) +
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
    labs(title="Clicks Conversion by Region", x="Region", y="Proportion", fill="Clicks Conversion")


```r
# Create bins for 'Daytime' 
ClickTraining <- ClickTraining %>%
  mutate(Daytime_Bin = cut(Daytime,
                           breaks = c(-Inf, 0.25, 0.5, 0.75, Inf),
                           labels = c("Night", "Morning", "Afternoon", "Evening"),
                           include.lowest = TRUE))

# the conversion rate by 'Daytime_Bin'
conversion_rate_by_time <- ClickTraining %>%
  group_by(Daytime_Bin) %>%
  summarize(Conversion_Rate = mean(Clicks_Conversion))

# the conversion rate by 'Daytime_Bin'
ggplot(conversion_rate_by_time, aes(x = Daytime_Bin, y = Conversion_Rate)) +
  geom_bar(stat = "identity", fill = "#70C1B3") +
  labs(title = "Clicks Conversion Rate by Time of Day",
       x = "Time of Day",
       y = "Conversion Rate") +
  theme_minimal()

Interpretations:

  1. Clicks Conversion by Weekday: The conversion rates (clicks) are consistently high at around 90% across the weekdays except Monday and Tuesday. It appears that the proportions of ads clicked (represented by the color teal) are particularly low at around only 60% on Monday and Tuesday, indicating that the likelihood of a user clicking on an ad is exceptionally low on these weekdays.

  2. Clicks Conversion by Social Network: There is a slight variation in ad click conversion rates across different social networks, with Facebook showing a highest conversion rate while Twitter showing a lowest rate. This could suggest that users on Facebook are slightly more likely to click on the ads, or that the ad content is more engaging or better targeted on this platforms.

  3. Clicks Conversion by Region: The conversion rates across different regions show minimal variance, suggesting that the effectiveness of the ads in terms of click-through rates is relatively uniform across the geographic areas represented. This indicates that Deliveroo’s ad targeting strategy is consistent in different regions, or that the region may not be a significant factor in influencing whether users click on ads.

Missing Values

We now check missing values in the training and prediction dataset.

sapply(ClickTraining, function(x) sum(is.na(x)))
##                    Region                   Daytime                   Carrier 
##                         0                         0                         0 
##  Time_On_Previous_Website                   Weekday            Social_Network 
##                         0                         0                         0 
## Number_of_Previous_Orders         Clicks_Conversion           Restaurant_Type 
##                         0                         0                      1848 
##               Daytime_Bin 
##                         0

We find that only Restaurant_Type contains missing values with a total number of 1848 among the 18000 observations, at a missing rate of about 10.27%.

sapply(ClickPrediction, function(x) sum(is.na(x)))
##                    Region                   Daytime                   Carrier 
##                         0                         0                         0 
##  Time_On_Previous_Website                   Weekday            Social_Network 
##                         0                         0                         0 
## Number_of_Previous_Orders           Restaurant_Type 
##                         0                       197

For the prediction dataset, Restaurant_Type is still the only variable that sees missing value, with a total number of 197 among the 2000 observations, at a missing rate of 9.85%.