kaggle—酒店预订需求预测分析

kaggle—酒店预订需求预测分析(Hotel booking demand)

项目背景:该项目为酒店线上预订业务的研究内容,从酒店运营的角度,分析酒店的房型供给、不同时间段的需求,核心消费群体,影响退订的因素,并建立分类算法模型对酒店订单退订进行预测。

数据来源:kaggle:Hotel booking demand,此项目数据为kaggle上的一个Hotel booking数据集,感兴趣的朋友可以去下载进行练习。

数据介绍:

字段名 字段含义
hotel 酒店名
is_canceled 是否退订
lead_time 入住时间
arrival_date_year 入住的年份
arrival_date_month 入住的月份
arrival_date_week_number 一年中的第几周
arrival_date_day_of_month 一年中的第几号
stays_in_weekend_nights 周末过夜数
stays_in_week_nights 周中过夜数
adults 成人数
children 儿童数
babies 婴儿数
meal 订餐情况
country 国籍
market_segment 细分市场
distribution_channel 市场
is_repeated_guest 是否回头客
previous_cancellations 客户在预订前取消的预订数量
previous_bookings_not_canceled 客户在预订之前未取消的预订数量
reserved_room_type 房型
assigned_room_type 房间类型编码
booking_changes 对预订做出的更改数量
deposit_type 是否交押金
agent 旅行社id
company 公司
days_in_waiting_list 确认订单前的审核天数
customer_type 预订类型
adr 平均每日放假
required_car_parking_spaces 客户要求的车位数量
total_of_special_requests 特殊要求的数量
reservation_status 订单状态
reservation_status_date 订单状态的最后设置日期

一共包含32个字段,119390条记录。

项目流程

  • 数据预处理
    • 缺失值处理
    • 数据类型转换
    • 异常值处理
  • 特征工程
    • 数值型特征标准化
    • 类别型特征 one-hot编码
    • 特征选择
  • 模型训练
  • 模型预测与评估

一、数据预处理

  1. 导入需要的库
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.model_selection import GridSearchCV
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
import seaborn as sns
  1. 查看并理解数据
df = pd.read_csv('hotel_bookings.csv',encoding='gbk')
df.head()
df.info()
结果:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 119390 entries, 0 to 119389
Data columns (total 32 columns):
 #   Column                          Non-Null Count   Dtype  
---  ------                          --------------   -----  
 0   hotel                           119390 non-null  object 
 1   is_canceled                     119390 non-null  int64  
 2   lead_time                       119390 non-null  int64  
 3   arrival_date_year               119390 non-null  int64  
 4   arrival_date_month              119390 non-null  object 
 5   arrival_date_week_number        119390 non-null  int64  
 6   arrival_date_day_of_month       119390 non-null  int64  
 7   stays_in_weekend_nights         119390 non-null  int64  
 8   stays_in_week_nights            119390 non-null  int64  
 9   adults                          119390 non-null  int64  
 10  children                        119386 non-null  float64
 11  babies                          119390 non-null  int64  
 12  meal                            119390 non-null  object 
 13  country                         118902 non-null  object 
 14  market_segment                  119390 non-null  object 
 15  distribution_channel            119390 non-null  object 
 16  is_repeated_guest               119390 non-null  int64  
 17  previous_cancellations          119390 non-null  int64  
 18  previous_bookings_not_canceled  119390 non-null  int64  
 19  reserved_room_type              119390 non-null  object 
 20  assigned_room_type              119390 non-null  object 
 21  booking_changes                 119390 non-null  int64  
 22  deposit_type                    119390 non-null  object 
 23  agent                           103050 non-null  float64
 24  company                         6797 non-null    float64
 25  days_in_waiting_list            119390 non-null  int64  
 26  customer_type                   119390 non-null  object 
 27  adr                             119390 non-null  float64
 28  required_car_parking_spaces     119390 non-null  int64  
 29  total_of_special_requests       119390 non-null  int64  
 30  reservation_status              119390 non-null  object 
 31  reservation_status_date         119390 non-null  object 
dtypes: float64(4), int64(16), object(12)
memory usage: 29.1+ MB

发现数据集一共有32个字段,119389行数据,company列有比较明显缺失值,另外arrival_date等表示时间的列需要合并并且转换为日期格式。

  1. 日期合并及格式转换

由于数据集中的arrival_date_month月份信息为英文表示,先将其转换为中文月份表示,方便后期合并日期

#修改arrival_date_month的英文月份为中文月份
import calendar
month = []
for i in df.arrival_date_month:
    mon = list(calendar.month_name).index(i)
    month.append(mon)
df.insert(
  • 1
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值