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:
| Column | Description |
|---|---|
Booking_ID | Unique identifier of the booking. |
no_of_adults | The number of adults. |
no_of_children | The number of children. |
no_of_weekend_nights | Number of weekend nights (Saturday or Sunday). |
no_of_week_nights | Number of week nights (Monday to Friday). |
type_of_meal_plan | Type of meal plan included in the booking. |
required_car_parking_space | Whether a car parking space is required. |
room_type_reserved | The type of room reserved. |
lead_time | Number of days before the arrival date the booking was made. |
arrival_year | Year of arrival. |
arrival_month | Month of arrival. |
arrival_date | Date of the month for arrival. |
market_segment_type | How the booking was made. |
repeated_guest | Whether the guest has previously stayed at the hotel. |
no_of_previous_cancellations | Number of previous cancellations. |
no_of_previous_bookings_not_canceled | Number of previous bookings that were canceled. |
avg_price_per_room | Average price per day of the booking. |
no_of_special_requests | Count of special requests made as part of the booking. |
booking_status | Whether 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.head()The Challenge
- Use your skills to produce recommendations for the hotel on what factors affect whether customers cancel their booking.
Time is ticking. Good luck!
1- DATA PREPARATION
1-1 Data imputation
We use median imputation for most of these numerical columns : no_of_adults, no_of_children, no_of_weekend_nights, no_of_week_nights, lead_time, required_car_parking_space, repeated_guest, no_of_previous_cancellations, no_of_previous_bookings_not_canceled, avg_price_per_room, no_of_special_requests.
# Example: Impute with median
hotels['no_of_adults'].fillna(hotels['no_of_adults'].median(), inplace=True)
hotels['no_of_children'].fillna(0, inplace=True) # Assuming missing means no children
hotels['lead_time'].fillna(hotels['lead_time'].median(), inplace=True)
hotels['no_of_weekend_nights'].fillna(hotels['no_of_weekend_nights'].median(), inplace=True)
hotels['no_of_special_requests'].fillna(0, inplace=True)
hotels['no_of_week_nights'].fillna(hotels['no_of_week_nights'].median(), inplace=True)
hotels['no_of_previous_cancellations'].fillna(hotels['no_of_previous_cancellations'].median(), inplace=True)
hotels['no_of_previous_bookings_not_canceled'].fillna(hotels['no_of_previous_bookings_not_canceled'].median(), inplace=True)
hotels['avg_price_per_room'].fillna(hotels['avg_price_per_room'].median(), inplace=True)
hotels['required_car_parking_space'].fillna(hotels['required_car_parking_space'].median(), inplace=True)
hotels['repeated_guest'].fillna(hotels['repeated_guest'].median(), inplace=True)We use the Mode imputation for these following categorical columns : type_of_meal_plan, room_type_reserved, market_segment_type, booking_status
# Impute with mode
hotels['type_of_meal_plan'].fillna(hotels['type_of_meal_plan'].mode()[0], inplace=True)
hotels['room_type_reserved'].fillna(hotels['room_type_reserved'].mode()[0], inplace=True)
hotels['market_segment_type'].fillna(hotels['market_segment_type'].mode()[0], inplace=True)
hotels['booking_status'].fillna(hotels['booking_status'].mode()[0], inplace=True)We use 0 imputation for these following columns : required_car_parking_space, no_of_special_requests, no_of_previous_cancellations. If missing values represent a lack of data because in this case the absence of a value is meaningful.
# Impute with 0
hotels['required_car_parking_space'].fillna(0, inplace=True)
hotels['no_of_special_requests'].fillna(0, inplace=True)
hotels['no_of_previous_cancellations'].fillna(0, inplace=True)Columns Related to Date (arrival_year, arrival_month, arrival_date).
We use Mode Imputation for the following columns : arrival_year, arrival_month, arrival_date
# Impute with mode
hotels['arrival_year'].fillna(hotels['arrival_year'].mode()[0], inplace=True)
hotels['arrival_month'].fillna(hotels['arrival_month'].mode()[0], inplace=True)
hotels['arrival_date'].fillna(hotels['arrival_date'].mode()[0], inplace=True)We can now check whether our data still have missing values