酒店预订订单的分析与建模【决策树、xgboost】
本项目包含
1.数据处理
2.数据探索性分析
3.网格搜索对决策树、xgboost进行模型参数调优
4.基于五折交叉验证的决策树、xgboost模型预测
专栏和往期项目
👉往期文章可以关注我的专栏
下巴同学的数据加油小站
会不定期分享数据挖掘、机器学习、风控模型、深度学习、NLP等方向的学习项目,关注不一定能学到你想学的东西,但是可以学到我想学和正在学的东西😀
往期项目-数据分析建模方向
2.大五人格测试数据集的探索【可视化+k-means聚类分析】
3.使用线性回归、LGBM对二手车价格进行预测
本文代码、数据点击下方链接可获取:
4.关于酒店预订数据集的探索【EDA+五折交叉验证决策树、xgboost预测】
目录
数据与背景描述
背景描述
在线酒店预订渠道已经极大地改变了预订的可能性和客户的行为。
酒店预订取消的典型原因包括计划的改变、日程安排的冲突等,对酒店客人来说,因为可以选择免费或最好是低价从而更容易取消预订,但对酒店来说,这是一个不太理想的、可能会减少收入的因素,需要解决的问题。
数据说明
column 列名
Booking_ID 每个预订的唯一标识符
no_of_adults 成人的数量
no_of_children 儿童的数量
no_of_weekend_nights 客人入住或预订入住酒店的周末晚数(周六或周日)
no_of_week_nights 客人在酒店住宿或预订住宿的周晚数(周一至周五)
type_of_meal_plan 客户预订的膳食计划的类型
required_car_parking_space 顾客是否需要一个停车位?(0-不,1-是)
room_type_reserved 顾客预订的房间类型。这些值是由INN酒店集团加密(编码)的
lead_time 预订日期和抵达日期之间的天数
arrival_year 抵达日期的年份
arrival_month 抵达日期的月份
arrival_date 该月的日期
market_segment_type 市场部分的指定
repeated_guest 该客户是否为重复客人?(0 - 否, 1- 是)
no_of_previous_cancellations 在当前预订之前,客户取消的先前预订的数量
no_of_previous_bookings_not_canceled 在当前预订前未被客户取消的先前预订的数量
avg_price_per_room 每天预订的平均价格;房间的价格是动态的。(单位:欧元)
no_of_special_requests 客户提出的特殊要求的总数(例如,高楼层,从房间看风景等)
booking_status 表示预订是否被取消的标志
导入并检查数据
导入数据
import pandas as pd
df = pd.read_csv('/home/mw/input/data9304/Hotel Reservations.csv')
df.head()
检查数据
数据无缺失,无重复
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 36275 entries, 0 to 36274
Data columns (total 19 columns):
Booking_ID 36275 non-null object
no_of_adults 36275 non-null int64
no_of_children 36275 non-null int64
no_of_weekend_nights 36275 non-null int64
no_of_week_nights 36275 non-null int64
type_of_meal_plan 36275 non-null object
required_car_parking_space 36275 non-null int64
room_type_reserved 36275 non-null object
lead_time 36275 non-null int64
arrival_year 36275 non-null int64
arrival_month 36275 non-null int64
arrival_date 36275 non-null int64
market_segment_type 36275 non-null object
repeated_guest 36275 non-null int64
no_of_previous_cancellations 36275 non-null int64
no_of_previous_bookings_not_canceled 36275 non-null int64
avg_price_per_room 36275 non-null float64
no_of_special_requests 36275 non-null int64
booking_status 36275 non-null object
dtypes: float64(1), int64(13), object(5)
memory usage: 5.3+ MB
df.duplicated().sum()
0
EDA
数据含义与分析目的
数据含义
首先看看数据都有哪些
数据一共19列
预定ID,是唯一标识符,仅用于区分数据
顾客数量有两列:成人数量和儿童数量两列
顾客预定天数:分为工作日和周末两列
顾客需求类数据:用餐类型,停车位,房间类型,顾客特殊要求数量四列
日期、时间类型数据:预定与抵达日间隔天数,抵达日期年份、月份,抵达日期四列
预定方法(在线、离线)
是否为历史用户
本次前客户是否取消数目:取消数目、未取消数目两列
预定房价的平均价格
是否被取消(目标变量)
明确目的
然后明确数据探索性分析的目的:我们想找出是否取消预定与上述其他特征是否存在一定的关系。
所以我们可以进行对比分析,这里只进行简单的分析,变量间关系暂不分析
成人、儿童数目的分析
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
plt.figure(figsize = (16, 12))
plt.suptitle("成人、儿童顾客的数目",fontweight="bold", fontsize=30)
plt.subplot(2,2,1)
plt.gca().set_title('成人数目对比分布')
sns.countplot(x = 'booking_status', hue = 'no_of_adults', edgecolor="black", alpha=0.7, data = df)
plt.subplot(2,2,2)
plt.gca().set_title('成人数目总分布')
sns.countplot(x = 'no_of_adults', edgecolor="black", alpha=0.7,data = df)
plt.subplot(2,2,3)
plt.gca().set_title('儿童数目对比分布')
sns.countplot(x = 'booking_status', hue = 'no_of_children', edgecolor="black", alpha=0.7, data = df)
plt.subplot(2,2,4)
plt.gca().set_title('儿童总数目分布')
sns.countplot(x = 'no_of_children', edgecolor="black", alpha=0.7,data = df)
顾客预定天数的分布
plt.figure(figsize = (16, 12))
plt.suptitle("顾客预定天数的分布",fontweight="bold", fontsize=30)
plt.subplot(2,2,1)
plt.gca().set_title('工作日预定天数对比')
sns.countplot(x = 'booking_status', hue = 'no_of_week_nights', edgecolor="