AI带你省钱旅游!精准预测民宿房源价格!( 二 )


gm_listings.shape# (3584, 74)gm_listings.columns

AI带你省钱旅游!精准预测民宿房源价格!

文章插图
gm_calendar.head()
AI带你省钱旅游!精准预测民宿房源价格!

文章插图
gm_reviews.head()
AI带你省钱旅游!精准预测民宿房源价格!

文章插图
我们对数据的初览可以看到,大曼彻斯特地区的房源数据集包含 3584 行和 78 列,包含有关房东、房源类型、区域和评级的信息 。
数据清洗
AI带你省钱旅游!精准预测民宿房源价格!

文章插图
数据清洗是机器学习建模应用的【特征工程】阶段的核心步骤,它涉及的方法技能欢迎大家查阅ShowMeAI对应的教程文章,快学快用 。
  • 机器学习实战 | 机器学习特征工程最全解读
字段清洗因为数据中的字段众多,有些字段比较乱,我们需要做一些数据清洗的工作,数据包含一些带有URL的列,对最后的预测作用不大,我们把它们清洗掉 。
# 删除url字段def drop_function(df):df = df.drop(columns=['listing_url', 'description', 'host_thumbnail_url', 'host_picture_url', 'latitude', 'longitude', 'picture_url', 'host_url', 'host_location', 'neighbourhood', 'neighbourhood_cleansed', 'host_about', 'has_availability', 'availability_30', 'availability_60', 'availability_90', 'availability_365', 'calendar_last_scraped'])return dfgm_df = drop_function(gm_listings)删除过后的数据如下,干净很多
AI带你省钱旅游!精准预测民宿房源价格!

文章插图
缺失值处理数据中也包含了一些缺失值,我们对它们进行分析处理:
# 查看缺失值百分比(gm_df.isnull().sum()/gm_df.shape[0])* 100得到如下结果
id0.000000scrape_id0.000000last_scraped0.000000name0.000000neighborhood_overview41.266741host_id0.000000host_name0.000000host_since0.000000host_response_time10.212054host_response_rate10.212054host_acceptance_rate5.636161host_is_superhost0.000000host_neighbourhood91.657366host_listings_count0.000000host_total_listings_count0.000000host_verifications0.000000host_has_profile_pic0.000000host_identity_verified0.000000neighbourhood_group_cleansed0.000000property_type0.000000room_type0.000000accommodates0.000000bathrooms100.000000bathrooms_text0.306920bedrooms4.687500beds2.120536amenities0.000000price0.000000minimum_nights0.000000maximum_nights0.000000minimum_minimum_nights0.000000maximum_minimum_nights0.000000minimum_maximum_nights0.000000maximum_maximum_nights0.000000minimum_nights_avg_ntm0.000000maximum_nights_avg_ntm0.000000calendar_updated100.000000number_of_reviews0.000000number_of_reviews_ltm0.000000number_of_reviews_l30d0.000000first_review19.810268last_review19.810268review_scores_rating19.810268review_scores_accuracy20.089286review_scores_cleanliness20.089286review_scores_checkin20.089286review_scores_communication20.089286review_scores_location20.089286review_scores_value20.089286license100.000000instant_bookable0.000000calculated_host_listings_count0.000000calculated_host_listings_count_entire_homes0.000000calculated_host_listings_count_private_rooms0.000000calculated_host_listings_count_shared_rooms0.000000reviews_per_month19.810268dtype: float64我们分几种不同的比例情况对缺失值进行处理: