Introduction

The objective of this project is to conduct comprehensive data analysis and visualization on the Hotel data set, which has details about hotel bookings, meal requirements, and booking performers.

Utilizing the R programming language, our analysis and visualization efforts aim to uncover trends that can guide the hotel in making informed decisions regarding its marketing strategies. Specifically, we are focused on identifying the most popular meal types for different customer segments and understanding the peak times for the customers.

This information is crucial for the hotel’s marketing decisions, enabling them to target specific sectors and tailor their advertising efforts accordingly. By understanding the preferences in meal types, booking patterns, and types of customers, the hotel can optimize its marketing strategies to maximize profitability.

In our analysis, we will delve into these specific aspects of the data set and provide concise summaries for a clear understanding of the insights gained.

  1. Load Required Packages
  2. Clean Up and Prepare Data for Analysis
  3. Summarizing Data Set
  4. Data Visualization
  5. Summary of Findings

Required Packages

library(tidyverse) # used to tidy up data
library(lubridate) # used for date/time functions
library(DT) # used for displaying R data objects (matrices or data frames) as tables on HTML pages
library(gtsummary) # used to summarize and visualize information

Data Importing and Preparation

The source data was in an .csv file which we would be now importing into the file.

The following is the code used to evaluate the variables in the source data. We noted that there is a total of 119390 observations in the data set, and 32 variables, which are listed below.

# Read the Hotels file from the csv file provided
hotels <- read_csv("hotels.csv")

# Store data as data frame
hotel_df <- data.frame(hotels)

# Find total number of observations  
nrow(hotel_df)

# Get variable names
names(hotel_df)

# Getting the summary of the data set
summary(hotel_df)

The data set contains following variable:

Variable Description Type
Hotel Type of Hotel Character
is_canceled Indicates if the booking was cancelled or not Double
lead_time Indicated the time elapsed between the booking date and arrival date Double
arrival_date_year Year of arrival date Double
arrival_date_month Month of arrival date Character
arrival_date_week_number Week Number of year of arrival date Double
arrival_date_day_of_month Month of arrival date Character
stays_in_weekend_nights Number of weekend nights the guest booked/stayed Double
stays_in_week_nights Number of week nights the guest booked/stayed Double
adults Number of adults per booking Double
children Number of children per booking Double
babies Number of babies per booking Double
meal Type of meal package booked Character
country Guest’s country of origin Character
market_segment How was the booking done - via travel agent(TA) or Tour Operators(TO) Character
distribution_channel distributing the booking according to market segment Character
is_repeated_guest Indicates whether they have previously booked or not Double
previous_cancellations How many cancellations are there prior to this booking Double
previous_bookings_not_cancelled How many bookings were not cancelled prior to this booking Double
reserved_room_type Type of room reserved by guest Character
assigned_room_type type of room assigned to the guest Character
booking_changes Number of changes made to the booking from the booking date to check in or check out date Double
deposit_type Indicating what type of deposit did the guest make at the time of booking Character
agent ID of the travel agency that made the booking Character
company D of the company/entity that made the booking or responsible for paying the booking Character
days_in_waiting_list Number of days booking was in waiting list before it was confirmed Double
customer_type Type of booking done by customer Character
adr Average Daily Rate as defined by dividing the sum of all lodging transactions by the total number of staying nights Double
required_car_parking_space Number of car parking spaces required by customer Double
total_of_special_requests Number of special request made by the customer Double
reservation_status Reservation last status Character
reservation_status_date Date at which last reservation was set Double

After getting an insight on the different variables in the data set we will look for missing variables if any in the data set.

colSums(is.na(hotel_df))
##                          hotel                    is_canceled 
##                              0                              0 
##                      lead_time              arrival_date_year 
##                              0                              0 
##             arrival_date_month       arrival_date_week_number 
##                              0                              0 
##      arrival_date_day_of_month        stays_in_weekend_nights 
##                              0                              0 
##           stays_in_week_nights                         adults 
##                              0                              0 
##                       children                         babies 
##                              4                              0 
##                           meal                        country 
##                              0                              0 
##                 market_segment           distribution_channel 
##                              0                              0 
##              is_repeated_guest         previous_cancellations 
##                              0                              0 
## previous_bookings_not_canceled             reserved_room_type 
##                              0                              0 
##             assigned_room_type                booking_changes 
##                              0                              0 
##                   deposit_type                          agent 
##                              0                              0 
##                        company           days_in_waiting_list 
##                              0                              0 
##                  customer_type                            adr 
##                              0                              0 
##    required_car_parking_spaces      total_of_special_requests 
##                              0                              0 
##             reservation_status        reservation_status_date 
##                              0                              0

Upon looking at the data set, we identified that the ‘children’ variable has only four missing values. To address this, we opted for imputation using the median, considering that the absence of a value might mean the absence of children. Given that the minimum is zero, the maximum is 10, and the mean is 0.1, opting for the median allows us to make sure outliers do not impact the data.

Additionally, we observed three columns representing different aspects of the booking date. To enhance clarity, we consolidated these columns into a single one, presenting the date in the ‘year-month-date’ format. This consolidation simplifies the representation of the booking date.

Furthermore, we decided to refine the format of the ‘reservation_status_date’ column, transforming it into the ‘year-month-date’ format for consistency and ease of understanding.

For cleaning the data, the following code was used:

# Imputing the 4 missing value in children with median
hotel_df$children[is.na(hotel_df$children)] <- median(hotel_df$children, na.rm = TRUE)

# Combining the year,month,date column into one for arrival date
hotel_clean_df <- hotel_df %>% 
  mutate(arrival_date_month = recode(arrival_date_month,
  January = 01,
  February = 02,
  March = 03,
  April = 04,
  May = 05,
  June = 06,
  July = 07,
  August = 08,
  September = 09,
  October = 10,
  November = 11,
  December = 12
)) %>% 
  unite(col = arrival_date,
        arrival_date_year,arrival_date_month,arrival_date_day_of_month,
        sep = "-") 

# Changing it to year month date format
hotel_clean_df <- hotel_clean_df %>% mutate(arrival_date = ymd(arrival_date))
hotel_clean_df <- hotel_clean_df %>% mutate(reservation_status_date = ymd(reservation_status_date))

Below is a snapshot of the clean data:

# Read first 10 rows of the cleaned data set

datatable(head(hotel_clean_df, 10),options = list(scrollX=TRUE, pageLength=10))

As previously mentioned, our primary focus revolves around distinct hotel types, average revenue, preferred meal types, customer types, and the preference for weekend or weeknight stays. To understand our comprehension of these variables before visualizing the data for insights, we will use the following code for summarization.

Summarizing the variables

# Average adr of each customer
mean(hotel_clean_df$adr)

# Finding different types of hotel
table(hotel_clean_df['hotel'])

# Finding Average adr based on the hotel type
hotel_clean_df %>% group_by(hotel) %>% summarise(average = mean(adr, na.rm = TRUE))

# Finding different types of meal types offered and which is popular
hotel_clean_df %>% group_by(meal) %>% summarise(popular_meal_type = n())

# Finding if there are more weekend night stays or week night stays
hotel_clean_df %>% group_by(hotel) %>% summarise(max = max(stays_in_weekend_nights,na.rm = TRUE))
hotel_clean_df %>% group_by(hotel) %>% summarise(max = max(stays_in_week_nights,na.rm = TRUE))

# Finding which type of customer is the most prominent
hotel_clean_df %>% group_by(customer_type) %>% summarise(number = n())
# We are summarizing everything we did above and showing it in a tabular form to make it easy to view
hotel_clean_df %>% 
  tbl_summary(include = c(customer_type,adr,stays_in_weekend_nights,stays_in_week_nights,meal),
              by = hotel) %>% add_n() %>%
  modify_header(label = "**Variable**") %>% 
  bold_labels()
Variable N City Hotel, N = 79,3301 Resort Hotel, N = 40,0601
customer_type 119,390

    Contract
2,300 (2.9%) 1,776 (4.4%)
    Group
293 (0.4%) 284 (0.7%)
    Transient
59,404 (75%) 30,209 (75%)
    Transient-Party
17,333 (22%) 7,791 (19%)
adr 119,390 100 (79, 126) 75 (50, 125)
stays_in_weekend_nights 119,390 1.00 (0.00, 2.00) 1.00 (0.00, 2.00)
stays_in_week_nights 119,390 2.00 (1.00, 3.00) 3.00 (1.00, 5.00)
meal 119,390

    BB
62,305 (79%) 30,005 (75%)
    FB
44 (<0.1%) 754 (1.9%)
    HB
6,417 (8.1%) 8,046 (20%)
    SC
10,564 (13%) 86 (0.2%)
    Undefined
0 (0%) 1,169 (2.9%)
1 n (%); Median (IQR)

The overall average revenue per available room (ADR) indicates that each guest spent approximately 101 dollars.There are total number of 79,330 City and 40,060 Resort Hotels with their ADR being 100 dollar and 75 dollar respectively. This difference suggests that there may be room for improvement in the marketing strategies for Resort Hotels to boost their total revenue.

Our findings also shed light on customer preferences, highlighting that Transient guests are the most prevalent in both types of hotels. Additionally, we looked into the meal preferences of guests, discovering that the Bed and Breakfast (BB) meal type is the most favored, chosen by almost 92,310 guests. This information can be valuable for catering services and marketing efforts, as it reflects the popularity of specific meal plans among the guests.

Proposed Exploratory Data Analysis

Below we would look at the data with the help of several graphs to gain understanding of the data. First and foremost we wanted to visualize the average ADR in each type of hotel to gain insight on which hotel would need more work.

# Visualizing the ADR for each hotel
hotel_visualization_df <- hotel_clean_df %>% group_by(hotel) %>% summarise(average = mean(adr, na.rm = TRUE))
barplot(hotel_visualization_df$average ~ hotel_visualization_df$hotel, main = "ADR for Hotel", 
        xlab = "Type of Hotel", ylab = "Average")

Based on this Resort Hotel needs more work as its ADR is relatively low in comparison to City Hotel.

Next I would like to view which meal type is the most common in each type of hotel. The most common meal type in both the hotels is BB (Bed and Breakfast).

# Visualization for meal type
ggplot(data = hotel_clean_df, aes(x = meal, fill = meal)) + geom_bar() + 
  facet_wrap(~ hotel) +   labs(title = "Most Common Meal Type", 
         x = "Meal Type", y = "Number of times booked")

Further I want to look into the most common type of customer in each type of hotel.The most common type of customer are Transient in both the hotels.

# Visualization for type of customer
ggplot(data = hotel_clean_df, aes(x = customer_type, fill = customer_type)) + geom_bar() + 
  facet_wrap(~ hotel)+ labs(title = "Most Common Customer Type", 
         x = "Customer Type", y = "Number of times booked")

Next, we will look at which meal type is the most common in customer for each hotel. To do so we create a function which would calculate the number of times that meal was booked by that type of customer for that hotel.

# Creating the function
meal_type <- function(type_of_hotel) {
  type_of_meal <- hotel_clean_df %>% filter(hotel == type_of_hotel) %>% 
    group_by(customer_type) %>% count(meal) 
  ggplot(type_of_meal, 
         aes(x = meal, y = n, fill = meal)) +
    geom_bar(stat="identity") + facet_wrap(~customer_type) + 
    labs(title = "Most Common Type of Meal", x = "Type of Meal", y = "Number of times booked")
}

Now, viewing which meal type is the most common for in City Hotel.

# Visualizing the data
meal_type('City Hotel')

Now viewing which type of meal is common in Resort Hotel.

# Visualizing the data
meal_type('Resort Hotel')

This shows for every customer type and each hotel BB(Bed and Breakfast) is the most common type of meal.

Next, we want to look at what type of stay i.e. weekend or weekday is more common with the different types of customers. To do this we create a function that would call upon how many weekend or week night stays were booked by that type of customer in the hotel.

# First we create a function which will calculate how many bookings for weekend night stay in different customer type for each hotel
staying_weekend <- function(type_of_hotel) {
  stay_weekend <- hotel_clean_df %>% filter(hotel == type_of_hotel) %>% 
    group_by(customer_type) %>% count(stays_in_weekend_nights) 
  ggplot(stay_weekend, 
         aes(x = stays_in_weekend_nights, y = n)) +
    geom_bar(stat="identity") + facet_wrap(~ customer_type) + 
    labs(title = "Bookings for Weekend Night Stay", x = "Number of Bookings" , y = "count")
}

staying_week <- function(type_of_hotel) {
  stay_week <- hotel_clean_df %>% filter(hotel == type_of_hotel) %>% 
    group_by(customer_type) %>% count(stays_in_week_nights) 
  ggplot(stay_week, 
         aes(x = stays_in_week_nights, y = n)) +
    geom_bar(stat="identity") + facet_wrap(~ customer_type) + 
    labs(title = "Bookings for Week Night Stay", x = "Number of Bookings" , y = "count")
}

Now we view which stay is more popular in City Hotel. We can say that City Hotel is more popular for week stay as that significantly has way more bookings than on weekend stays and Transient is the most common customer type.

# Visualizing the data
staying_week('City Hotel')

# Visualizing the data
staying_weekend('City Hotel')

Now we would look at which stay is more popular in Resort Hotel. We can say that Resort Hotel is more popular for weekend stay as that has significantly more bookings than on week stays and Transient is the most common customer type.

# Visualizing the data
staying_week('Resort Hotel')

 # Visualizing the data
staying_weekend('Resort Hotel')

Lastly, we would look at which meal type is the most popular during weeknight and weekend stay. To do so we create a function that would help us calculate which meal type is the most favorable.

# Creating the function
staying_weekend_meal <- function(type_of_hotel) {
  stay_weekend <- hotel_clean_df %>% filter(hotel == type_of_hotel) %>% 
    group_by(meal) %>% count(stays_in_weekend_nights) 
  ggplot(stay_weekend, 
         aes(x = stays_in_weekend_nights, y = n)) +
    geom_bar(stat="identity") + facet_wrap(~ meal) + 
    labs(title = "Meal Bookings for Weekend Night Stay", x = "Number of Bookings" , y = "count")
}

staying_week_meal <- function(type_of_hotel) {
  stay_week <- hotel_clean_df %>% filter(hotel == type_of_hotel) %>% 
    group_by(meal) %>% count(stays_in_week_nights) 
  ggplot(stay_week, 
         aes(x = stays_in_week_nights, y = n)) +
    geom_bar(stat="identity") + facet_wrap(~ meal) + 
    labs(title = "Bookings for Week Night Stay", x = "Number of Bookings" , y = "count")
}

Now viewing for City Hotel. We can see that meal type BB (Bed and Breakfast) is the most common in both type of stays.

# Visualizing the data
staying_week_meal('City Hotel')

# Visualizing the data
staying_weekend_meal('City Hotel')

Now viewing for Resort Hotel. We can see that meal type BB (Bed and Breakfast) is the most common in both type of stays.

# Visualizing the data
staying_week_meal('Resort Hotel')

# Visualizing the data
staying_weekend_meal('Resort Hotel')

Summary of Findings

The analysis conducted has shown key insights into hotel bookings, providing a foundation for creating targeted marketing strategies to attract more guests and boost revenue. Notably, the findings show that the majority of guests prefer Transient bookings for both City and Resort Hotels. Additionally, the Bed and Breakfast (BB) meal type is highly popular among guests in both hotel types, and there is a preference for City hotels on weeknights and Resort hotels on weekends.

These insights can be used to form effective marketing strategies. For instance, hotels could capitalize on the existing popularity of Transient bookings by promoting special offers specifically tailored for Transient customers, especially during weeknights for City Hotels and weekends for Resort Hotels. Similarly, marketing efforts could be intensified to highlight the appeal of the BB meal type, particularly for Transient customers.

Using these findings into marketing campaigns has the potential to attract a more guests, capitalize on existing preferences of the guests, and ultimately lead to an increase in hotel revenue.