本次分享的项目来自 Kaggle 的经典赛题:房价预测。分为数据分析和数据挖掘两部分介绍。本篇为数据分析篇。

赛题解读

比赛概述

影响房价的因素有很多,在本题的数据集中有 79 个变量几乎描述了爱荷华州艾姆斯 (Ames, Iowa) 住宅的方方面面,要求预测最终的房价。

技术栈

特征工程 (Creative feature engineering)

回归模型 (Advanced regression techniques like random forest and

gradient boosting)

最终目标

预测出每间房屋的价格,对于测试集中的每一个Id,给出变量SalePrice相应的值。

提交格式

Id,SalePrice

1461,169000.1

1462,187724.1233

1463,175221

etc.

数据分析

数据描述

首先我们导入数据并查看:

train_df = pd.read_csv('./input/train.csv', index_col=0)

test_df = pd.read_csv('./input/test.csv', index_col=0)

train_df.head()

我们可以看到有 80 列,也就是有 79 个特征。

接下来将训练集和测试集合并在一起,这么做是为了进行数据预处理的时候更加方便,让测试集和训练集的特征变换为相同的格式,等预处理进行完之后,再把他们分隔开。

我们知道SalePrice作为我们的训练目标,只出现在训练集中,不出现在测试集,因此我们需要把这一列拿出来再进行合并。在拿出这一列前,我们先来观察它,看看它长什么样子,也就是查看它的分布。

prices = DataFrame({'price': train_df['SalePrice'], 'log(price+1)': np.log1p(train_df['SalePrice'])})

prices.hist()

因为label本身并不平滑,为了我们分类器的学习更加准确,我们需要首先把label给平滑化(正态化)。我在这里使用的是log1p, 也就是 log(x+1)。要注意的是我们这一步把数据平滑化了,在最后算结果的时候,还要把预测到的平滑数据给变回去,那么log1p()的反函数就是expm1(),后面用到时再具体细说。

然后我们把这一列拿出来:

y_train = np.log1p(train_df.pop('SalePrice'))

y_train.head()

Id

1 12.247699

2 12.109016

3 12.317171

4 11.849405

5 12.429220

Name: SalePrice, dtype: float64

这时,y_train就是SalePrice那一列。

然后我们把两个数据集合并起来:

df = pd.concat((train_df, test_df), axis=0)

查看shape:

df.shape

(2919, 79)

df就是我们合并之后的DataFrame。

数据预处理

根据 kaggle 给出的说明,有以下特征及其说明:

SalePrice - the property's sale price in dollars. This is the target variable that you're trying to predict.

MSSubClass: The building class

MSZoning: The general zoning classification

LotFrontage: Linear feet of street connected to property

LotArea: Lot size in square feet

Street: Type of road access

Alley: Type of alley access

LotShape: General shape of property

LandContour: Flatness of the property

Utilities: Type of utilities available

LotConfig: Lot configuration

LandSlope: Slope of property

Neighborhood: Physical locations within Ames city limits

Condition1: Proximity to main road or railroad

Condition2: Proximity to main road or railroad (if a second is present)

BldgType: Type of dwelling

HouseStyle: Style of dwelling

OverallQual: Overall material and finish quality

OverallCond: Overall condition rating

YearBuilt: Original construction date

YearRemodAdd: Remodel date

RoofStyle: Type of roof

RoofMatl: Roof material

Exterior1st: Exterior covering on house

Exterior2nd: Exterior covering on house (if more than one material)

MasVnrType: Masonry veneer type

MasVnrArea: Masonry veneer area in square feet

ExterQual: Exterior material quality

ExterCond: Present condition of the material on the exterior

Foundation: Type of foundation

BsmtQual: Height of the basement

BsmtCond: General condition of the basement

BsmtExposure: Walkout or garden level basement walls

BsmtFinType1: Quality of basement finished area

BsmtFinSF1: Type 1 finished square feet

BsmtFinType2: Quality of second finished area (if present)

BsmtFinSF2: Type 2 finished square feet

BsmtUnfSF: Unfinished square feet of basement area

TotalBsmtSF: Total square feet of basement area

Heating: Type of heating

HeatingQC: Heating quality and condition

CentralAir: Central air conditioning

Electrical: Electrical system

1stFlrSF: First Floor square feet

2ndFlrSF: Second floor square feet

LowQualFinSF: Low quality finished square feet (all floors)

GrLivArea: Above grade (ground) living area square feet

BsmtFullBath: Basement full bathrooms

BsmtHalfBath: Basement half bathrooms

FullBath: Full bathrooms above grade

HalfBath: Half baths above grade

Bedroom: Number of bedrooms above basement level

Kitchen: Number of kitchens

KitchenQual: Kitchen quality

TotRmsAbvGrd: Total rooms above grade (does not include bathrooms)

Functional: Home functionality rating

Fireplaces: Number of fireplaces

FireplaceQu: Fireplace quality

GarageType: Garage location

GarageYrBlt: Year garage was built

GarageFinish: Interior finish of the garage

GarageCars: Size of garage in car capacity

GarageArea: Size of garage in square feet

GarageQual: Garage quality

GarageCond: Garage condition

PavedDrive: Paved driveway

WoodDeckSF: Wood deck area in square feet

OpenPorchSF: Open porch area in square feet

EnclosedPorch: Enclosed porch area in square feet

3SsnPorch: Three season porch area in square feet

ScreenPorch: Screen porch area in square feet

PoolArea: Pool area in square feet

PoolQC: Pool quality

Fence: Fence quality

MiscFeature: Miscellaneous feature not covered in other categories

MiscVal: $Value of miscellaneous feature

MoSold: Month Sold

YrSold: Year Sold

SaleType: Type of sale

SaleCondition: Condition of sale

接下来我们对特征进行分析。上述列出了一个目标变量SalePrice和 79 个特征,数量较多,这一步的特征分析是为了之后的特征工程做准备。

我们来查看哪些特征存在缺失值:

print(pd.isnull(df).sum())

这样并不方便观察,我们先查看缺失值最多的 10 个特征:

df.isnull().sum().sort_values(ascending=False).head(10)

为了更清楚的表示,我们用缺失率来考察缺失情况:

df_na = (df.isnull().sum() / len(df)) * 100

df_na = df_na.drop(df_na[df_na == 0].index).sort_values(ascending=False)

missing_data = pd.DataFrame({'缺失率': df_na})

missing_data.head(10)

对其进行可视化:

f, ax = plt.subplots(figsize=(15,12))

plt.xticks(rotation='90')

sns.barplot(x=df_na.index, y=df_na)

plt.xlabel('Features', fontsize=15)

plt.ylabel('Percent of missing values', fontsize=15)

plt.title('Percent missing data by feature', fontsize=15)

我们可以看到PoolQC、MiscFeature、Alley、Fence、FireplaceQu 等特征存在大量缺失,LotFrontage 有 16.7% 的缺失率,GarageType、GarageFinish、GarageQual 和 GarageCond等缺失率相近,这些特征有的是 category 数据,有的是 numerical 数据,对它们的缺失值如何处理,将在关于特征工程的部分给出。

最后,我们对每个特征进行相关性分析,查看热力图:

corrmat = train_df.corr()

plt.subplots(figsize=(15,12))

sns.heatmap(corrmat, vmax=0.9, square=True)

我们看到有些特征相关性大,容易造成过拟合现象,因此需要进行剔除。在下一篇的数据挖掘篇我们来对这些特征进行处理并训练模型。

不足之处,欢迎指正。

python数据分析房价预测_Kaggle入门级赛题:房价预测——数据分析篇相关推荐

  1. 阿里云天池大赛赛题解析――深度学习篇

    作者:天池平台 出版社:电子工业出版社 品牌:电子工业出版社 出版时间:2021-09-01 阿里云天池大赛赛题解析――深度学习篇

  2. 阿里云天池大赛赛题解析——深度学习篇

    阿里云天池大赛赛题解析--深度学习篇 (豆瓣)图书阿里云天池大赛赛题解析--深度学习篇 介绍.书评.论坛及推荐 https://book.douban.com/subject/35596114/

  3. 阿里云天池大赛赛题解析(深度学习篇)--阅读笔记1--赛题一

    阿里云天池大赛赛题解析(深度学习篇)–阅读笔记1 [x]表示遇到不懂的知识,将在[知识补充]给出具体讲解. 文章目录 阿里云天池大赛赛题解析(深度学习篇)--阅读笔记1 前言 赛题一 瑞金医院MMC人 ...

  4. 数据分析模板一赛题分析(预测房屋租金)

    总结一份属于自己的模板,不管三七二十一,拿来先套用.方便自己学习和记录. 拿到一份赛题数据,我们要赛题分析.就做以下2点. 认识数据 对比赛数据做EDA 1.认识数据 了解比赛的背景 你是做金融数据分 ...

  5. 【机器学习算法实战3】产品营销模型之建置及预测(CDA赛题)

    一.案例介绍 这是CDA数据分析网站的一个赛题,A公司希望发掘用户购买产品的行为习惯,建立产品精准营销模型,对有意向的客户进行精准营销,增加收入,减少开支.将通过混淆矩阵(Confusion matr ...

  6. kaggle竞赛-宠物受欢迎程度(赛题讲解与数据分析)

    比赛官网地址 赛题介绍 petfinder是马来西亚领先的动物福利平台宠物网站地址 该网站使用可爱指数来排名宠物照片.它分析了图片组成和其他因素,并与数千个宠物档案的表现进行了比较. 在这场比赛中,你 ...

  7. 【算法竞赛学习】金融风控之贷款违约预测-赛题理解

    Task1 赛题理解 赛题以金融风控中的个人信贷为背景,要求选手根据贷款申请人的数据信息预测其是否有违约的可能,以此判断是否通过此项贷款,这是一个典型的分类问题.通过这道赛题来引导大家了解金融风控中的 ...

  8. 数据竞赛入门-金融风控(贷款违约预测)一、赛题介绍

    赛题概况 比赛要求参赛选手根据给定的数据集,建立模型,预测金融风险. 赛题以预测金融风险为任务,数据集报名后可见并可下载,该数据来自某信贷平台的贷款记录,总数据量超过120w,包含47列变量信息,其中 ...

  9. 【数据挖掘】金融风控 Task01 赛题理解

    [数据挖掘]金融风控 Task01 赛题理解 1.赛题介绍 1.1赛题概况 1.2 数据概况 1.3 预测指标 1.3.1 混淆矩阵 1.3.2 准确率.精确率.召回率.F1 Score 1.3.3 ...

  10. 第一次认真的二手车交易价格预测--赛题分析

    二手车交易价格预测--赛题分析 数据比赛步骤 一. 赛题分析 1.1 学习目标 1.2 了解赛题 1.2.1 赛题概况 1.2.2 数据概况 train.csv 1.2.3 预测指标 一般问题评价指标 ...

最新文章

  1. Navicat For Mysql快捷键
  2. java执行器是什么_java使用Executor(执行器)管理线程
  3. 1.16 static关键字(静态变量和静态方法)
  4. solver.prototxt文件里面参数含义及其设置
  5. java 字符串赋值_灵魂拷问:为什么 Java 字符串是不可变的?
  6. php板块模板,有没有办法制作模板,但没有在板块php渲染它
  7. pat 1085 Perfect Sequence (25) 二分查找
  8. 过Serverless技术降低微服务应用资源成本
  9. ncl如何添加线shp文件_NCL画图个例讲解
  10. iOS开发经验总结—内存管理
  11. 威马汽车CEO沈晖:汽车“报复性”消费不现实
  12. perl lwp 超时问题
  13. 算法小结——qsort函数
  14. go-echarts x 轴标签显示不全
  15. android studio开发个人备忘录算法设计_Android Studio 4.1 发布,全方位提升开发体验...
  16. 解决mysql客户端中文显示乱码
  17. python pip什么意思_“pip install”和“python -m pip install”有什么区别?
  18. 求和问题总结(leetcode 2Sum, 3Sum, 4Sum, K Sum)
  19. 网络攻击还是网络战争?
  20. matplotlib(直方图,条形图,饼图,散点图)基础知识

热门文章

  1. FeignClient方式调用第三方接口
  2. 扫描全能王文件上传不了服务器,如何将扫描全能王的文档轻松保存到坚果云?...
  3. Win32的setlocale详解
  4. Windows10开启虚拟化
  5. (美国)数字设备公司 DEC
  6. 一个由“2020年1月7日 京东出现的重大 Bug 漏洞“引起的思考......
  7. 供应链管理的三个层次
  8. PS学习-剪切蒙版制作艺术字
  9. 深度学习和机器学习研究方向与框架介绍
  10. 高速服务器充电桩位置,最全高速服务区充电站汇总,再也不担心过年回家趴半路啦!...