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.
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)
First, we set up the working directory and load the data set.
# Check the current working directory
getwd()
## [1] "E:/OneDrive - CentraleSupelec/eloise/ESSEC/T1/Marketing Analytics/Group Project/Topic 2 - Online Ad Click Predictor"
# 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.
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.
Daytime: A numerical representation of the time of day when the ad was displayed. Helps in understanding peak engagement times.
Carrier: The internet service provider or mobile network carrier of the user who viewed the ad. Reflects the carrier’s market share among the audience.
Time_On_Previous_Website: The amount of time (in seconds) the user spent on the previous website before clicking the ad. Indicates user engagement levels.
Weekday: The day of the week when the ad was displayed. Useful for analyzing day-wise trends in ad clicks.
Social_Network: The social network platform on which the ad was displayed. Shows platform preference among the audience.
Number_of_Previous_Orders: The count of previous orders made by the user. A higher number might indicate loyal customers.
Clicks_Conversion: A binary variable indicating whether the ad was clicked (1) or not (0). The primary target variable for prediction.
Restaurant_Type: The type of restaurant being advertised. Helps in understanding preferences for different cuisines or restaurant types.
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" ...
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
##
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:
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.
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.
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.
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.
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.
For numeric variables, we plot histograms or boxplots for numeric variables to understand their distribution and identify any outliers.
# Histograms
ggplot(ClickTraining, aes(x=Daytime)) + geom_histogram(bins=30) + labs(title="Histogram of Daytime")
ggplot(ClickTraining, aes(x=Time_On_Previous_Website)) + geom_histogram(bins=30) + labs(title="Histogram of Time On Previous Website")
ggplot(ClickTraining, aes(x=Number_of_Previous_Orders)) + geom_histogram(bins=30) + labs(title="Histogram of Number of Previous Orders")
# 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:
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.
The boxplot also reflects this even distribution. There are no outliers and the quartiles are evenly spaced.
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.
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
corrplot(cor_matrix, method = "circle", type = "upper", tl.col = "black", tl.srt = 45, title = "Correlation Plot")
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.
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") +
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") +
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") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title="Clicks Conversion by Region", x="Region", y="Proportion", fill="Clicks Conversion")
Interpretations:
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.
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.
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.
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
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%.