The purpose of this project is to perform data analysis and visualization for the Hotel data set. The hotel data set contains information in regards to the hotel bookings, meal required, and who performed the bookings and where are the guests from.
We used R to perform data analysis and visualization to explore and identify trends in hotel data set, and uncover insights to understand how many people enjoy certain meal types or when the hotel was most booked during weekend or weekday, where the people are from most and make changes based on the insights gathered in hotel marketing to earn as much profit as possible:
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
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
This shows that only the children variable has 4 missing values so we will impute the missing values with the median because the missing values might indicate that they do not have any children and since the minimum is zero and maximum is 10 and mean is 0.1 we want to negate the outlier.
Moreover while looking at the different variables we noted that it has three different columns to represent when the booking was done, we will combine this into one column which would show the date in year month date format instead of having three different columns showing a certain part of arrival date. This would make it easier to understand the data. We would also change the format of reservation_status_date to year month date format.
As such, we used the following code to tidy up our data:
# Read the Hotels file from the csv file provided
hotels <- read_csv("hotels.csv")
# Storing the data as data frame
hotel_df <- data.frame(hotels)
# 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))
Using the following code, we performed preliminary analysis on the cleaned data set and obtained summary statistics for each variable. The main insights would be based on the variable hotel, weekend_nights, week_nights, meal, country, repeated guest, room type, customer_type, deposit_type and adr.
# Average adr of each customer
mean(hotel_clean_df$adr)
## [1] 101.8311
# Finding different types of hotel
table(hotel_clean_df['hotel'])
## hotel
## City Hotel Resort Hotel
## 79330 40060
# Finding Average adr based on the hotel type
hotel_clean_df %>% group_by(hotel) %>% summarise(average = mean(adr, na.rm = TRUE))
## # A tibble: 2 × 2
## hotel average
## <chr> <dbl>
## 1 City Hotel 105.
## 2 Resort Hotel 95.0
The overall average adr shows that roughly each guest spent 101$ in the hotel. Furthermore, we found out that there are 79330 City Hotels and 40060 resort Hotels. This further summarized the data by showing us that average for city hotels is 105$ and resort hotel is 94$. Giving us further insight that we need to improve marketing strategies for resort hotel to increase the total revenue.
# Finding different types of meal types offered and which is popular
hotel_clean_df %>% group_by(meal) %>% summarise(popular_meal_type = n())
## # A tibble: 5 × 2
## meal popular_meal_type
## <chr> <int>
## 1 BB 92310
## 2 FB 798
## 3 HB 14463
## 4 SC 10650
## 5 Undefined 1169
We than summarized meal types which gave us information that meal type BB is the most popular among the guests as almost 92310 guest chose to go with it.
# Finding guests from which country frequently visit
table(hotel_clean_df['country'])
## country
## ABW AGO AIA ALB AND ARE ARG ARM ASM ATA ATF AUS AUT
## 2 362 1 12 7 51 214 8 1 2 1 426 1263
## AZE BDI BEL BEN BFA BGD BGR BHR BHS BIH BLR BOL BRA
## 17 1 2342 3 1 12 75 5 1 13 26 10 2224
## BRB BWA CAF CHE CHL CHN CIV CMR CN COL COM CPV CRI
## 4 1 5 1730 65 999 6 10 1279 71 2 24 19
## CUB CYM CYP CZE DEU DJI DMA DNK DOM DZA ECU EGY ESP
## 8 1 51 171 7287 1 1 435 14 103 27 32 8568
## EST ETH FIN FJI FRA FRO GAB GBR GEO GGY GHA GIB GLP
## 83 3 447 1 10415 5 4 12129 22 3 4 18 2
## GNB GRC GTM GUY HKG HND HRV HUN IDN IMN IND IRL IRN
## 9 128 4 1 29 1 100 230 35 2 152 3375 83
## IRQ ISL ISR ITA JAM JEY JOR JPN KAZ KEN KHM KIR KNA
## 14 57 669 3766 6 8 21 197 19 6 2 1 2
## KOR KWT LAO LBN LBY LCA LIE LKA LTU LUX LVA MAC MAR
## 133 16 2 31 8 1 3 7 81 287 55 16 259
## MCO MDG MDV MEX MKD MLI MLT MMR MNE MOZ MRT MUS MWI
## 4 1 12 85 10 1 18 1 5 67 1 7 2
## MYS MYT NAM NCL NGA NIC NLD NOR NPL NULL NZL OMN PAK
## 28 2 1 1 34 1 2104 607 1 488 74 18 14
## PAN PER PHL PLW POL PRI PRT PRY PYF QAT ROU RUS RWA
## 9 29 40 1 919 12 48590 4 1 15 500 632 2
## SAU SDN SEN SGP SLE SLV SMR SRB STP SUR SVK SVN SWE
## 48 1 11 39 1 2 1 101 2 5 65 57 1024
## SYC SYR TGO THA TJK TMP TUN TUR TWN TZA UGA UKR UMI
## 2 3 2 59 9 3 39 248 51 5 2 68 1
## URY USA UZB VEN VGB VNM ZAF ZMB ZWE
## 32 2097 4 26 1 8 80 2 4
It further gave insight that the maximum guests were from Portugal that 48590 with United Kingdom being a close second at 12129. To further increase the revenue for the hotel we could have meal types based on Portugal and UK cuisine and increasing profits for the hotel.
# Finding how many guests repeated and had cancelled previous booking and how many have not
table(hotel_clean_df['is_repeated_guest'])
## is_repeated_guest
## 0 1
## 115580 3810
hotel_clean_df %>% group_by(hotel) %>% filter(is_repeated_guest == 1) %>%
summarise(maximum_cancellations = max(previous_cancellations,na.rm=TRUE))
## # A tibble: 2 × 2
## hotel maximum_cancellations
## <chr> <dbl>
## 1 City Hotel 21
## 2 Resort Hotel 5
hotel_clean_df %>% group_by(hotel) %>% filter(is_repeated_guest == 1) %>%
summarise(maximum_non_cancellations = max(previous_bookings_not_canceled,na.rm = TRUE))
## # A tibble: 2 × 2
## hotel maximum_non_cancellations
## <chr> <dbl>
## 1 City Hotel 72
## 2 Resort Hotel 26
We further summarize the number of repeated guests which shows us that only 3810 guests repeated which is a low number compared to the number of guests which did not repeat and tells us we need to make changes in the hotels to make more and more guests repeat. Further we summarized that out of the 3810 repeated guests prior cancellations were 21 which is in city hotel is a huge number and maybe we need to look into the cancellation policy of the City Hotel. Furthermore there were 72 prior bookings repeated which is an amazing thing.
# 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))
## # A tibble: 2 × 2
## hotel max
## <chr> <dbl>
## 1 City Hotel 16
## 2 Resort Hotel 19
hotel_clean_df %>% group_by(hotel) %>% summarise(max = max(stays_in_week_nights,na.rm = TRUE))
## # A tibble: 2 × 2
## hotel max
## <chr> <dbl>
## 1 City Hotel 41
## 2 Resort Hotel 50
This summarized that both type of hotels are more popular with week night booking than weekend night bookings.
# Finding if the assigned room type matches the reserved room type
hotel_clean_df %>% filter(reserved_room_type == assigned_room_type) %>% summarise(number = n())
## number
## 1 104473
hotel_clean_df %>% filter(reserved_room_type != assigned_room_type) %>% summarise(number = n())
## number
## 1 14917
hotel_clean_df %>% group_by(reserved_room_type,assigned_room_type) %>% summarise(n = n())
## # A tibble: 75 × 3
## # Groups: reserved_room_type [10]
## reserved_room_type assigned_room_type n
## <chr> <chr> <int>
## 1 A A 73598
## 2 A B 1123
## 3 A C 1447
## 4 A D 7548
## 5 A E 1156
## 6 A F 417
## 7 A G 186
## 8 A H 94
## 9 A I 215
## 10 A K 210
## # ℹ 65 more rows
This shows that out of all the times 104,473 times assigned room type was the same as reserved room type but 14917 times that was not the case. It also gives us further insight on which room type is the most popular in this case it is room type A.
# Finding out which deposit type is the most popular
hotel_clean_df %>% group_by(hotel) %>% filter(deposit_type == "No Deposit") %>%
summarise(number_no_deposit = n())
## # A tibble: 2 × 2
## hotel number_no_deposit
## <chr> <int>
## 1 City Hotel 66442
## 2 Resort Hotel 38199
hotel_clean_df %>% group_by(hotel) %>% filter(deposit_type == "Non Refund") %>%
summarise(number_non_refund = n())
## # A tibble: 2 × 2
## hotel number_non_refund
## <chr> <int>
## 1 City Hotel 12868
## 2 Resort Hotel 1719
hotel_clean_df %>% group_by(hotel) %>% filter(deposit_type == "Refundable") %>%
summarise(number_refundable = n())
## # A tibble: 2 × 2
## hotel number_refundable
## <chr> <int>
## 1 City Hotel 20
## 2 Resort Hotel 142
This shows us that for both the hotel the deposit type refundable is the least popular with no deposit being the most popular and non refund being somewhere in between.
# Finding which type of customer is the most prominent
hotel_clean_df %>% group_by(customer_type) %>% summarise(number = n())
## # A tibble: 4 × 2
## customer_type number
## <chr> <int>
## 1 Contract 4076
## 2 Group 577
## 3 Transient 89613
## 4 Transient-Party 25124
This shows that transient is the most popular customer type in the hotels.
We can look at the data in several different ways with several different plots. Some of the visualization is shown below but we can combine data for repeated_guest, previous_cancellations, and previous_bookings_not_cancelled. Furthermore we can create a new variable that shows how many times assigned_room_type and reserved_room_type is the same and for which room type. This will further help us understand more about room_type.
An example of this would be the visualization below as we create a
new variable average which shows the average adr for city hotel and
resort hotel respectively and visualize it using a bar plot.
Another such example would be the visualization for meal type which
provides us with insight on which type of meal is the most popular.
Another example would be the visualization which shows the most
common type of deposit type for each hotel respectively.
The type of plot that would be helpful would be box plot, bar graph, line graph, and histogram as then we would be able to compare between two different types.
As shown above different visualizations but as we proceed with further analyzation we are already aware of the fact that the most guests are from Portugal, United Kingdom, and France. We can further analyze and visualize whenever guests from these country come to visit City Hotel and Resort Hotel respectively what meal and room type is the most popular. We can use those two things to attract more customers by centering advertising based on them and thus increase the revenue. We can further even see if they are booking more on weekends or weeknights and use this to provide certain discounts or offers to attract the customers.
I need to further learn about how to create graphs while keeping several factors in mind, different ways I can make the graph look more readable and easy to understand.
We can conclude from the above summary that City Hotels are more popular, with more guests staying at the hotel, and thus its average is higher. It taught us that we needed to focus more on Resort Hotels in order to make them more marketable and increase revenue. Moreover, the meal type BB is the most popular among guests. We can have this meal served most frequently in hotels so that more and more guests eat there, increasing profits. We also discovered that the majority of the hotel guests are from Portugal. This gave us the idea that we could have Portuguese cuisine and a more Portuguese theme in the hotel to attract more guests.
We also discovered that many guests are canceling their reservations, and in one case, there were 21 cancellations prior to their current reservation. This revealed that we needed to review the hotel’s cancellation policy to ensure that no one was canceling at random and that the hotel was not losing money as a result. We can also conclude that weeknights are more popular for hotel stays, which we can use to increase hotel revenue even further.
We also discovered that room type A is the most frequently booked, so we can use this information to possibly increase room type A charges to increase revenue and, in the future, have more room type A in the hotel so that all customers can have their preferred room type, thereby increasing customer satisfaction. Finally, transient customers are the most common; this fact can be used to attract more customers to hotels.
These are some of the insights gained from summarizing the data set that can be used to boost hotel revenue. Furthermore, as we continue to work on analyzing and visualizing the data we can focus on hotel, country, room_type, meal_type, stay_at_weekends, and stay_at_weeknights to understand what sort of audience to target using different advertising techniques and even gain insight on what sort of offers to provide for advertising to attract more customers.