内容
本次数据分析练习的数据集来自于kaggle。数据集中包含两种类型的旅馆,Resort Hotel和City Hotel。
下面的内容包括数据的探索性分析和建模预测。
探索性分析部分涉及两种旅店的顾客国家构成、人员构成、房间的价格分布、各月份的预订情况、顾客居住时长、预订被取消的情况等。
建模预测旨在预测预订是否会被取消这一问题。
(一)EDA
初步了解下数据集的情况
hotel.info()
hotel.isnull().sum()/len(hotel)
该数据集一共包含32个变量,近12万条记录。
数据维度
数据详细记录了旅店预订的各种信息
(1) 用户特征
children,adults,babies,country,
(2) 旅店特征
hotel,
(3)时间特征
lead_time,arrival_date_year,arrival_date_month,arrival_date_week_number,arrival_date_day_of_month,stays_in_weekend_nights,stayed or booked to stay at the hotel,stays_in_week_nights,booked to stay at the hotel,days_in_waiting_list
(4)其它订单特征
is_canceled,meal,market_segment,distribution_channel,is_repeated_guest,previous_cancellations,previous_bookings_not_canceled,reserved_room_type,assigned_room_type,booking_changes,deposit_type,agent,company,customer_type,adr,required_car_parking_spaces,total_of_special_requests,reservation_status,reservation_status_date
- 缺失值占比情况
children:0.0034%
country:0.4087%
agent:13.6862%
company:94.3069%
1 旅馆预订的顾客来自于哪些国家
分别分析两类旅馆的国家占比情况,筛选出占比在3%以上的国家,低于3%的国家合并为“other”
hotel['country'].fillna('unknown',inplace=True)
country_info = pd.DataFrame(hotel.groupby(['hotel'])['country'].value_counts())
country_info = country_info.rename(columns={'country':'number'}).reset_index()
CH_country = country_info[country_info['hotel']=='City Hotel'][['country','number']]
CH_country['rate'] = CH_country.number/CH_country.number.sum()
CH_country.loc[CH_country['rate']<0.03,'country'] = 'other'
CH_country=CH_country.groupby(['country']).sum().sort_values('rate',ascending=False).reset_index()
plt.pie(CH_country['rate'],labels=CH_country['country'], autopct='%.2f%%',pctdistance=0.8,startangle=90,radius=1.5,counterclock=False)
plt.show()
RH_country = country_info[country_info['hotel']=='Resort Hotel'][['country','number']]
RH_country['rate'] = RH_country.number/RH_country.number.sum()
RH_country.loc[RH_country['rate']<0.03,'country'] = 'other'
RH_country=RH_country.groupby(['country']).sum().sort_values('rate',ascending=False).reset_index()
plt.pie(RH_country['rate'],labels=RH_country['country'], autopct='%.2f%%',pctdistance=0.85,startangle=90,radius=1.5,counterclock=False)
plt.show()
City Hotel
City Hotel的预订中占比最高的国家来自于PRT,达到了39%,其次是FRA、DEU、GBR、ESP。
Resort Hotel
Resort Hotel的预订中占比最高的国家来自于PRT,达到了44%,其次是GBR、ESP、IRL、FRA、DEU。
2 预订信息中各类人群的情况
预订信息中包括三类人群:adults,children,babies
2.1 children
考虑到children中缺失值较少,直接删除
hotel_clean = hotel.dropna(subset=['children'])
children中人数分布情况:人数集中在3个以内,有约93%均为0个;仅有1个10人的记录,作为异常值删除
hotel_clean.children.value_counts()
hotel_clean = hotel_clean[hotel_clean['children']<=3]
2.2 adults
adults中人数分布情况:人数集中在4个以内,有超过9