1. Introduction

1.1 The problem

Hotels offer an intangible experience; an unoccupied room for the night cannot be sold later. When a guest cancels a reservation, the hotel risks losing the associated revenue and may encounter difficulties in reselling the room. Alternatively, hotels may overbook to mitigate potential losses. In the dataset analyzed in this study, a substantial proportion of bookings are canceled. Cancellations introduce uncertainty into revenue forecasting and complicate staffing, pricing, and inventory management decisions. These factors increase operational risk for hotels.

Research question: Which booking characteristics are associated with cancellation, and how can these findings help hotels improve their operational decisions?

1.2 Data and method

Our analysis focuses on exploratory data analysis to identify relationships between hotel booking characteristics and cancellation rates. We examine variables such as lead time, market segment, hotel type, and arrival month using summary statistics, tables, and visualizations. These findings help us understand cancellation patterns and their potential implications for hotel operations.

1.3 Analytical approach

Our analysis uses descriptive statistics and visualizations to examine relationships between hotel booking characteristics and cancellation rates. We compare cancellation patterns across lead time, market segment, hotel type, and arrival periods. We also investigate unusual records and room assignment differences to better understand the dataset and identify meaningful patterns.

1.4 How this helps the reader

Hotel revenue managers can use these findings to better understand which booking categories experience higher cancellation rates. This information could support decisions about reservation policies, staffing, inventory management, and demand forecasting. By understanding cancellation patterns, hotels may be better equipped to reduce uncertainty and improve operational efficiency.

2. Packages Required

Package Purpose
tidyverse Data import, cleaning (dplyr, tidyr, readr), and plotting (ggplot2)
scales Formatting percentages and numbers on plots and tables
knitr Printing clean tables in the HTML report
library(tidyverse)  
library(scales)     
library(knitr)     

3. Data Preparation

3.1 Source of the data

3.2 About the source data

  • Origin: The data was published with the paper above by Nuno Antonio, Ana de Almeida, and Luis Nunes. TidyTuesday later re-shared it for R practice.
  • Purpose: The dataset was originally collected to develop models that predict hotel booking cancellations. It was also published to support research and education in areas such as revenue management, customer segmentation, and machine learning.
  • Date published: February 2019 (collection period: July 2015 to August 2017).
  • Hotels covered: Two hotels in Portugal: a resort hotel in the Algarve region and a city hotel in Lisbon.
  • Size: 119,390 observations and 32 variables.
  • Content: Details about each hotel booking, including the guests, arrival date, room type, deposit type, market segment, and whether or not the booking was canceled.
  • Missing values:
    • Only children has true blank values (4 of them).
    • The variables country, agent, and company record missing values as the text “NULL” instead of a blank. This is easy to miss, because R does not treat the text “NULL” as missing unless we tell it to. company is about 94% missing.
  • Other peculiarities:
    • reservation_status and reservation_status_date describe what happened to the booking after the fact, so they reveal whether it was canceled. These variables reveal the booking outcome and were not used in our exploratory analysis.
    • A small number of records look like errors, such as bookings with zero guests.

3.3 Importing and cleaning

First, we import the data. We tell R to treat blanks and the text “NULL” as missing values so that they are counted correctly.

hotels_raw <- read_csv("hotels.csv", na = c("", "NA", "NULL"),
                       show_col_types = FALSE)

Next, we check which variables have missing values.

# Count missing values by variable, keeping only variables that have any
hotels_raw %>%
  summarise(across(everything(), ~ sum(is.na(.)))) %>%
  pivot_longer(everything(), names_to = "variable", values_to = "n_missing") %>%
  filter(n_missing > 0) %>%
  mutate(pct_missing = percent(n_missing / nrow(hotels_raw), accuracy = 0.1)) %>%
  kable(caption = "Variables with missing values in the raw data")
Variables with missing values in the raw data
variable n_missing pct_missing
children 4 0.0%
country 488 0.4%
agent 16340 13.7%
company 112593 94.3%
# Count exact duplicate records
sum(duplicated(hotels_raw))
## [1] 31994
# Inspect a sample of duplicate records
hotels_raw %>%
  filter(duplicated(.) | duplicated(., fromLast = TRUE)) %>%
  head(10)
## # A tibble: 10 × 32
##    hotel        is_canceled lead_time arrival_date_year arrival_date_month
##    <chr>              <dbl>     <dbl>             <dbl> <chr>             
##  1 Resort Hotel           0        14              2015 July              
##  2 Resort Hotel           0        14              2015 July              
##  3 Resort Hotel           0        72              2015 July              
##  4 Resort Hotel           0        72              2015 July              
##  5 Resort Hotel           0        70              2015 July              
##  6 Resort Hotel           0        70              2015 July              
##  7 Resort Hotel           1         5              2015 July              
##  8 Resort Hotel           1         5              2015 July              
##  9 Resort Hotel           0         0              2015 July              
## 10 Resort Hotel           0         0              2015 July              
## # ℹ 27 more variables: arrival_date_week_number <dbl>,
## #   arrival_date_day_of_month <dbl>, stays_in_weekend_nights <dbl>,
## #   stays_in_week_nights <dbl>, adults <dbl>, children <dbl>, babies <dbl>,
## #   meal <chr>, country <chr>, market_segment <chr>,
## #   distribution_channel <chr>, is_repeated_guest <dbl>,
## #   previous_cancellations <dbl>, previous_bookings_not_canceled <dbl>,
## #   reserved_room_type <chr>, assigned_room_type <chr>, …

Duplicate Records

We identified 31,994 exact duplicate records, representing approximately 26.8% of the dataset. However, identical records do not necessarily represent duplicate bookings, as different customers may have made reservations with the same characteristics. Since the dataset does not contain a unique booking identifier, we cannot confirm whether these records are errors. Therefore, we decided to retain them to avoid potentially removing legitimate bookings.

# Check bookings with zero-night stays
zero_nights <- hotels_raw %>%
  filter(stays_in_weekend_nights + stays_in_week_nights == 0)

cat("Zero-night bookings:", nrow(zero_nights))
## Zero-night bookings: 715
zero_nights %>%
  select(hotel, is_canceled, adults, children, babies,
         stays_in_weekend_nights, stays_in_week_nights) %>%
  head(10) %>%
  kable(caption = "Sample of zero-night bookings")
Sample of zero-night bookings
hotel is_canceled adults children babies stays_in_weekend_nights stays_in_week_nights
Resort Hotel 0 2 0 0 0 0
Resort Hotel 0 2 0 0 0 0
Resort Hotel 0 2 0 0 0 0
Resort Hotel 0 1 0 0 0 0
Resort Hotel 0 2 0 0 0 0
Resort Hotel 0 2 0 0 0 0
Resort Hotel 0 2 0 0 0 0
Resort Hotel 0 1 0 0 0 0
Resort Hotel 0 2 0 0 0 0
Resort Hotel 0 2 2 0 0 0
# Check bookings with unusually large guest counts
large_groups <- hotels_raw %>%
  mutate(total_guests = adults + coalesce(children, 0) + babies) %>%
  filter(total_guests >= 10)

cat("Bookings with 10 or more guests:", nrow(large_groups))
## Bookings with 10 or more guests: 16
large_groups %>%
  select(hotel, is_canceled, adults, children, babies,
         total_guests) %>%
  head(10) %>%
  kable(caption = "Sample of unusually large bookings")
Sample of unusually large bookings
hotel is_canceled adults children babies total_guests
Resort Hotel 1 2 10 0 12
Resort Hotel 1 40 0 0 40
Resort Hotel 1 26 0 0 26
Resort Hotel 1 50 0 0 50
Resort Hotel 1 26 0 0 26
Resort Hotel 1 26 0 0 26
Resort Hotel 1 27 0 0 27
Resort Hotel 1 27 0 0 27
Resort Hotel 1 26 0 0 26
Resort Hotel 1 26 0 0 26

Unusual Values

We identified 715 zero-night bookings and 16 bookings with 10 or more guests. These observations could represent administrative records, group reservations, or data-entry errors. After applying our existing cleaning procedures, 645 zero-night bookings and all 16 large-group bookings remained. We retained these observations because there was insufficient evidence to classify them as errors. The 70 excluded zero-night bookings were removed through our existing cleaning procedures rather than specifically because of their stay length.

Here is how we handle each case and why:

  1. company and agent are removed. company is about 94% missing, so it carries almost no usable information. agent is an ID code with hundreds of different values, which is not useful for our analysis.
  2. Missing country values are recoded as “Unknown.” This keeps those bookings in the data instead of throwing them away.
  3. Missing children values are set to 0. There are only 4, and we are assuming that no value means no children.
  4. Bookings with zero guests are removed. A booking with no adults, children, or babies is almost certainly a data error.
  5. The market segment “Undefined” is removed. It has only 2 bookings, which is too few to be useful.
  6. We create helper variables. total_nights and total_guests combine related columns, lead_bucket groups lead time into ranges, arrival_month puts the months in calendar order, and is_canceled becomes a labeled category. These make tables and plots easier to read and are used in the exploratory analysis section.
hotels <- hotels_raw %>%
  select(-company, -agent) %>%                                     
  mutate(country  = replace_na(country, "Unknown"),                
         children = replace_na(children, 0)) %>%                   
  filter(adults + children + babies > 0) %>%                       
  filter(market_segment != "Undefined") %>%                        
  mutate(is_canceled  = factor(is_canceled, levels = c(0, 1),      
                               labels = c("stayed", "canceled")),
         total_nights = stays_in_weekend_nights + stays_in_week_nights,
         total_guests = adults + children + babies,
         arrival_month = factor(arrival_date_month, levels = month.name),
         lead_bucket   = cut(lead_time, breaks = c(-1, 7, 30, 90, 180, Inf),
                             labels = c("0-7 days", "8-30 days", "31-90 days",
                                        "91-180 days", "180+ days")))

# Error checks: no missing outcomes, and cleaning removed only a small share of rows
stopifnot(!anyNA(hotels$is_canceled))
stopifnot(nrow(hotels) > 0.98 * nrow(hotels_raw))

cat("Rows removed during cleaning:", nrow(hotels_raw) - nrow(hotels))
## Rows removed during cleaning: 182
cat("Zero-night bookings retained:",
    sum(hotels$total_nights == 0))
## Zero-night bookings retained: 645
cat("Bookings with 10+ guests retained:",
    sum(hotels$total_guests >= 10))
## Bookings with 10+ guests retained: 16

3.4 The cleaned data

To keep the view short, we show the first 6 rows of the main variables instead of all 32 columns.

hotels %>%
  select(hotel, is_canceled, lead_time, arrival_date_year, total_nights,
         total_guests, market_segment, deposit_type) %>%
  head(6) %>%
  kable(caption = "First six rows of the cleaned data (main variables)")
First six rows of the cleaned data (main variables)
hotel is_canceled lead_time arrival_date_year total_nights total_guests market_segment deposit_type
Resort Hotel stayed 342 2015 0 2 Direct No Deposit
Resort Hotel stayed 737 2015 0 2 Direct No Deposit
Resort Hotel stayed 7 2015 1 1 Direct No Deposit
Resort Hotel stayed 13 2015 1 1 Corporate No Deposit
Resort Hotel stayed 14 2015 2 2 Online TA No Deposit
Resort Hotel stayed 14 2015 2 2 Online TA No Deposit

3.5 Summary of the variables

n_rows        <- nrow(hotels)
cancel_rate   <- mean(hotels$is_canceled == "canceled")
rate_by_hotel <- hotels %>%
  group_by(hotel) %>%
  summarise(rate = mean(is_canceled == "canceled"))
city_rate   <- rate_by_hotel$rate[rate_by_hotel$hotel == "City Hotel"]
resort_rate <- rate_by_hotel$rate[rate_by_hotel$hotel == "Resort Hotel"]

After cleaning, the data contain 119,208 bookings, and 37.1% of them were canceled. The cancellation rate differs by hotel: 41.8% at the city hotel versus 27.8% at the resort hotel. The median lead time (days between booking and arrival) is 69 days, and the average stay is 3.4 nights.

The tables below summarize the numeric variables and the cancellation rate for the main categorical variables.

# Numeric variables of concern
hotels %>%
  select(lead_time, total_nights, total_guests,
         previous_cancellations, total_of_special_requests) %>%
  pivot_longer(everything(), names_to = "variable") %>%
  group_by(variable) %>%
  summarise(mean = round(mean(value), 2), median = median(value),
            min = min(value), max = max(value)) %>%
  kable(caption = "Numeric variables")
Numeric variables
variable mean median min max
lead_time 104.11 69 0 737
previous_cancellations 0.09 0 0 26
total_guests 1.97 2 1 55
total_nights 3.43 3 0 69
total_of_special_requests 0.57 0 0 5
# Categorical variables of concern: number of bookings and cancellation rate
cat_rate <- function(var) {
  hotels %>%
    group_by(level = as.character(.data[[var]])) %>%
    summarise(bookings = n(),
              cancel_rate = percent(mean(is_canceled == "canceled"), accuracy = 0.1),
              .groups = "drop") %>%
    mutate(variable = var, .before = 1)
}

bind_rows(cat_rate("hotel"), cat_rate("deposit_type"),
          cat_rate("market_segment"), cat_rate("customer_type")) %>%
  kable(caption = "Cancellation rate by categorical variables")
Cancellation rate by categorical variables
variable level bookings cancel_rate
hotel City Hotel 79161 41.8%
hotel Resort Hotel 40047 27.8%
deposit_type No Deposit 104459 28.4%
deposit_type Non Refund 14587 99.4%
deposit_type Refundable 162 22.2%
market_segment Aviation 235 22.1%
market_segment Complementary 728 12.2%
market_segment Corporate 5282 18.8%
market_segment Direct 12582 15.4%
market_segment Groups 19791 61.1%
market_segment Offline TA/TO 24182 34.3%
market_segment Online TA 56408 36.8%
customer_type Contract 4072 31.0%
customer_type Group 574 10.1%
customer_type Transient 89476 40.8%
customer_type Transient-Party 25086 25.4%

4. Exploratory Data Analysis

4.1 Uncovering information that is not self-evident

To identify patterns that were not immediately apparent in the dataset, we examined cancellation rates across different booking characteristics, including hotel type, market segment, lead time, and arrival month. We also created variables for total nights, total guests, and lead-time categories to better understand booking behavior.

One particularly interesting finding involved room assignments. Bookings with different assigned and reserved room types had substantially lower cancellation rates than bookings without room changes. However, this relationship should be interpreted cautiously because room assignments may occur after a booking has already been confirmed or canceled.

hotels %>%
  mutate(room_change = if_else(
    reserved_room_type == assigned_room_type,
    "No room change",
    "Room changed"
  )) %>%
  group_by(room_change) %>%
  summarise(
    bookings = n(),
    cancellations = sum(is_canceled == "canceled"),
    cancellation_rate = percent(
      mean(is_canceled == "canceled"),
      accuracy = 0.1
    ),
    .groups = "drop"
  ) %>%
  kable(caption = "Cancellation Rates by Room Assignment")
Cancellation Rates by Room Assignment
room_change bookings cancellations cancellation_rate
No room change 104412 43396 41.6%
Room changed 14796 801 5.4%

The results show that bookings without a room change had a cancellation rate of 41.6%, compared to just 5.4% for bookings with a room change. This suggests a strong association between room assignments and cancellations. However, this relationship does not necessarily mean that changing rooms reduces cancellations, since room assignments may occur after booking decisions have already been made.

4.2 Plots and tables

  • Bar chart of cancellation rate by lead-time bucket (below).
  • Bar chart of cancellation rate by market segment (below).
  • Line chart of cancellation rate by month, split by hotel (below).
  • Heat map of cancellation rate for lead time by market segment (below).
# Cancellation rate by lead time
hotels %>%
  group_by(lead_bucket) %>%
  summarise(rate = mean(is_canceled == "canceled")) %>%
  ggplot(aes(lead_bucket, rate)) +
  geom_col(fill = "steelblue") +
  geom_text(aes(label = percent(rate, accuracy = 1)), vjust = -0.4) +
  scale_y_continuous(labels = percent, limits = c(0, 0.7)) +
  labs(title = "Cancellation Rate by Lead Time",
       x = "Lead Time", y = "Share of Bookings Canceled")

The bar chart shows how cancellation rates vary depending on how far in advance a reservation is made. Bookings made further in advance generally have higher cancellation rates, suggesting that longer lead times are associated with greater cancellation risk.

# Cancellation rate by market segment
hotels %>%
  group_by(market_segment) %>%
  summarise(rate = mean(is_canceled == "canceled")) %>%
  ggplot(aes(reorder(market_segment, rate), rate)) +
  geom_col(fill = "steelblue") +
  coord_flip() +
  scale_y_continuous(labels = percent) +
  labs(title = "Cancellation Rate by Market Segment",
       x = NULL, y = "Share Canceled")

Cancellation rates vary across market segments, suggesting that different types of customers have different booking behaviors. This highlights the importance of considering market segments when evaluating cancellation risk.

# Cancellation rate by hotel and year
hotels %>%
  group_by(arrival_date_year, hotel, arrival_month) %>%
  summarise(rate = mean(is_canceled == "canceled"),
            .groups = "drop") %>%
  ggplot(aes(arrival_month, rate,
             colour = hotel, group = hotel)) +
  geom_line() +
  geom_point() +
  facet_wrap(~ arrival_date_year) +
  scale_y_continuous(labels = percent) +
  labs(title = "Monthly Cancellation Rates by Year and Hotel",
       x = "Arrival Month",
       y = "Cancellation Rate",
       colour = "Hotel") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

Cancellation rates vary by arrival month, hotel type, and year. Separating the results by year helps identify whether monthly patterns are consistent over time rather than assuming that differences between months represent a recurring seasonal trend.

# Lead time by market segment
# Groups with fewer than 100 bookings are excluded
hotels %>%
  group_by(lead_bucket, market_segment) %>%
  summarise(rate = mean(is_canceled == "canceled"),
            n = n(), .groups = "drop") %>%
  filter(n >= 100) %>%
  ggplot(aes(lead_bucket, market_segment, fill = rate)) +
  geom_tile() +
  geom_text(aes(label = percent(rate, accuracy = 1)), size = 3) +
  scale_fill_gradient(low = "white",
                      high = "firebrick",
                      labels = percent) +
  labs(title = "Cancellation Rate: Lead Time by Market Segment",
       subtitle = "Groups with fewer than 100 bookings are excluded",
       x = "Lead Time",
       y = NULL,
       fill = "Rate")

The heat map shows cancellation rates across different lead-time categories and market segments. Blank cells represent combinations with fewer than 100 bookings, which were excluded to avoid drawing conclusions from small sample sizes. These blank cells do not necessarily indicate that no bookings occurred.

Summary and Conclusions

Overview of the Analysis

This project examined hotel booking cancellations using data from a city hotel and a resort hotel in Portugal. After cleaning the dataset, we explored how booking characteristics such as lead time, market segment, arrival month, and room assignments relate to cancellation rates. The goal was to identify patterns that could help hotels better understand cancellation behavior and improve their operational decisions.

Key Findings

Our analysis identified several important relationships. Bookings made further in advance generally had higher cancellation rates, suggesting that lead time is an important factor in cancellation behavior. Cancellation rates also differed across market segments, hotels, and arrival periods. Additionally, bookings with room changes had a substantially lower cancellation rate (5.4%) than those without room changes (41.6%). However, this relationship may reflect when room assignments occur rather than a direct effect on cancellations.

Business Implications

These findings could help hotel managers identify booking categories associated with higher cancellation risk. For example, hotels could pay closer attention to reservations made far in advance and use reminders or deposit policies to reduce uncertainty. Understanding differences across market segments could also help hotels improve demand forecasting, staffing, and room inventory management.

Limitations

The analysis has several limitations. The dataset includes only two hotels in Portugal, so the findings may not apply to every hotel. Some records contain unusual values or exact duplicates that could not be confidently identified as errors. Additionally, the analysis identifies associations rather than proving that specific booking characteristics cause cancellations. Room assignments may also contain information that would not be available when predicting cancellations in advance.

Conclusion and Future Research

Overall, the exploratory analysis shows that hotel booking cancellations are associated with several reservation characteristics, particularly lead time and market segment. These findings provide a foundation for understanding cancellation behavior and identifying potential operational improvements. Future research could develop and evaluate predictive models, such as logistic regression and random forest, to determine how accurately cancellations can be predicted before guests arrive.