Skip to content
0

Predicting Hotel Cancellations

🏨 Background

You are supporting a hotel with a project aimed to increase revenue from their room bookings. They believe that they can use data science to help them reduce the number of cancellations. This is where you come in!

They have asked you to use any appropriate methodology to identify what contributes to whether a booking will be fulfilled or cancelled. They intend to use the results of your work to reduce the chance someone cancels their booking.

The Data

They have provided you with their bookings data in a file called hotel_bookings.csv, which contains the following:

ColumnDescription
Booking_IDUnique identifier of the booking.
no_of_adultsThe number of adults.
no_of_childrenThe number of children.
no_of_weekend_nightsNumber of weekend nights (Saturday or Sunday).
no_of_week_nightsNumber of week nights (Monday to Friday).
type_of_meal_planType of meal plan included in the booking.
required_car_parking_spaceWhether a car parking space is required.
room_type_reservedThe type of room reserved.
lead_timeNumber of days before the arrival date the booking was made.
arrival_yearYear of arrival.
arrival_monthMonth of arrival.
arrival_dateDate of the month for arrival.
market_segment_typeHow the booking was made.
repeated_guestWhether the guest has previously stayed at the hotel.
no_of_previous_cancellationsNumber of previous cancellations.
no_of_previous_bookings_not_canceledNumber of previous bookings that were not canceled.
avg_price_per_roomAverage price per day of the booking.
no_of_special_requestsCount of special requests made as part of the booking.
booking_statusWhether the booking was cancelled or not.

Source (data has been modified): https://www.kaggle.com/datasets/ahsan81/hotel-reservations-classification-dataset

import pandas as pd
hotels = pd.read_csv("data/hotel_bookings.csv")
hotels

The Challenge

  • Use your skills to produce recommendations for the hotel on what factors affect whether customers cancel their booking.

Note:

To ensure the best user experience, we currently discourage using Folium and Bokeh in Workspace notebooks.

Judging Criteria

CATEGORYWEIGHTINGDETAILS
Recommendations35%
  • Clarity of recommendations - how clear and well presented the recommendation is.
  • Quality of recommendations - are appropriate analytical techniques used & are the conclusions valid?
  • Number of relevant insights found for the target audience.
Storytelling35%
  • How well the data and insights are connected to the recommendation.
  • How the narrative and whole report connects together.
  • Balancing making the report in-depth enough but also concise.
Visualizations20%
  • Appropriateness of visualization used.
  • Clarity of insight from visualization.
Votes10%
  • Up voting - most upvoted entries get the most points.

Checklist before publishing

  • Rename your workspace to make it descriptive of your work. N.B. you should leave the notebook name as notebook.ipynb.
  • Remove redundant cells like the judging criteria, so the workbook is focused on your work.
  • Check that all the cells run without error.

Time is ticking. Good luck!

Strategy:

To identify the factors that influence hotel cancellations, we can perform exploratory data analysis on the dataset provided. We can start by looking at the correlation between different features and the cancellation status. We can also use statistical tests such as t-tests or ANOVA to compare the means of different features for cancelled and non-cancelled bookings. Additionally, we can use machine learning algorithms such as logistic regression or decision trees to build predictive models and identify the most important features. Overall, a combination of exploratory data analysis and machine learning techniques can help us identify the factors that influence hotel cancellations.

Inspect the data

before we dive into a statistics analysis, let's take a look on the sammary report of the fields.

# examine the data fields and missing values
print(hotels.info())
#To transform the booking status to numeric type, we can use the `replace()` method in pandas. We can replace the string values of "Canceled" and "Not_Canceled" with 1 and 0, respectively. Here's an example code:
hotels["is_canceled"] = hotels["booking_status"].replace({"Canceled": 1, "Not_Canceled": 0})
hotels.head()
# calculate the correlation between each field and is_canceled
corr_matrix = hotels.corr()["is_canceled"].sort_values(ascending=False)
print(corr_matrix)

# visualize the result
import seaborn as sns
import matplotlib.pyplot as plt

plt.figure(figsize=(12,8))
sns.barplot(x=corr_matrix.index, y=corr_matrix.values)
plt.xticks(rotation=90)
plt.title("Correlation between each field and is_canceled")
plt.show()
# remove missing values
hotels.dropna(inplace=True)

# drop unnecessary columns
X = hotels.drop(['Booking_ID', 'booking_status', 'is_canceled'], axis=1)

# get dummies for categorical variables
X = pd.get_dummies(X, drop_first=True)
Y = hotels['is_canceled']
# import necessary libraries
from sklearn.ensemble import RandomForestClassifier
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

# create a random forest classifier object
rfc = RandomForestClassifier(n_estimators=100, random_state=42)
rfc.fit(X, Y) # fit the random forest model