个人对Kaggle预测房价的探讨,附思路和源代码。
受个人能力限制,存在诸多不足。
仅供参考。欢迎讨论。
1:分析准备
打开train文档,先熟悉数据。
先看看数据,到底什么东西:
import numpy as np
import pandas as pd
data =pd.read_csv(r'./source data/train.csv')
print(data.info())
结果如下:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1460 entries, 0 to 1459
Data columns (total 81 columns):
Id 1460 non-null int64
MSSubClass 1460 non-null int64
MSZoning 1460 non-null object
LotFrontage 1201 non-null float64
LotArea 1460 non-null int64
Street 1460 non-null object
Alley 91 non-null object
LotShape 1460 non-null object
LandContour 1460 non-null object
Utilities 1460 non-null object
LotConfig 1460 non-null object
LandSlope 1460 non-null object
Neighborhood 1460 non-null object
Condition1 1460 non-null object
Condition2 1460 non-null object
BldgType 1460 non-null object
HouseStyle 1460 non-null object
OverallQual 1460 non-null int64
OverallCond 1460 non-null int64
YearBuilt 1460 non-null int64
YearRemodAdd 1460 non-null int64
RoofStyle 1460 non-null object
RoofMatl 1460 non-null object
Exterior1st 1460 non-null object
Exterior2nd 1460 non-null object
MasVnrType 1452 non-null object
MasVnrArea 1452 non-null float64
ExterQual 1460 non-null object
ExterCond 1460 non-null object
Foundation 1460 non-null object
BsmtQual 1423 non-null object
BsmtCond 1423 non-null object
BsmtExposure 1422 non-null object
BsmtFinType1 1423 non-null object
BsmtFinSF1 1460 non-null int64
BsmtFinType2 1422 non-null object
BsmtFinSF2 1460 non-null int64
BsmtUnfSF 1460 non-null int64
TotalBsmtSF 1460 non-null int64
Heating 1460 non-null object
HeatingQC 1460 non-null object
CentralAir 1460 non-null object
Electrical 1459 non-null object
1stFlrSF 1460 non-null int64
2ndFlrSF 1460 non-null int64
LowQualFinSF 1460 non-null int64
GrLivArea 1460 non-null int64
BsmtFullBath 1460 non-null int64
BsmtHalfBath 1460 non-null int64
FullBath 1460 non-null int64
HalfBath 1460 non-null int64
BedroomAbvGr 1460 non-null int64
KitchenAbvGr 1460 non-null int64
KitchenQual 1460 non-null object
TotRmsAbvGrd 1460 non-null int64
Functional 1460 non-null object
Fireplaces 1460 non-null int64
FireplaceQu 770 non-null object
GarageType 1379 non-null object
GarageYrBlt 1379 non-null float64
GarageFinish 1379 non-null object
GarageCars 1460 non-null int64
GarageArea 1460 non-null int64
GarageQual 1379 non-null object
GarageCond 1379 non-null object
PavedDrive 1460 non-null object
WoodDeckSF 1460 non-null int64
OpenPorchSF 1460 non-null int64
EnclosedPorch 1460 non-null int64
3SsnPorch 1460 non-null int64
ScreenPorch 1460 non-null int64
PoolArea 1460 non-null int64
PoolQC 7 non-null object
Fence 281 non-null object
MiscFeature 54 non-null object
MiscVal 1460 non-null int64
MoSold 1460 non-null int64
YrSold 1460 non-null int64
SaleType 1460 non-null object
SaleCondition 1460 non-null object
SalePrice 1460 non-null int64
dtypes: float64(3), int64(35), object(43)
memory usage: 924.0+ KB
None
train的文档中,具有1460个样本,80个属性,而最后需要的结果只有一个:SalePrice,也就是房价。
所以第一件事,就是得进行整合和分析,看这么多属性分别都是什么,中文都是什么意思。
1.1:数据对应中英文转换
| SalePrice | 以美元出售的房产价格。 |
| MSSubClass | 建筑类 |
| MSZoning | 城市总体规划分区 |
| LotFrontage | 连接物业的街道线 |
| LotArea: | Lot size in square feet 方块大小 |
| Street | 道路入口类型 |
| Alley | 巷类型 |
| LotShape | 地产的外形 |
| LandContour | 地产的扁平化 |
| Utilities | 地产的公用事业类型 |
| LotConfig | 地产配置 |
| LandSlope | 地产的坡 |
| Neighborhood | 城市范围内的物理位置 |
| Condition1 | 接近主干道或铁路 |
| Condition2 | 接近主路或铁路 |
| BldgType | 住宅类型 |
| HouseStyle | 居家风格 |
| OverallQual | 整体质量和表面质量 |
| OverallCond | 总体状态额定值 |
| YearBuilt | 原施工日期 |
| YearRemodAdd | 重塑日期 |
| RoofStyle | 屋顶类型 |
| RoofMatl | 屋顶材料 |
| Exterior1st | 房屋外墙 |
| Exterior2nd | 外部第二层:房屋外部覆盖物 |
| MasVnrType | 圬工单板型 |
| MasVnrArea | 砌体单板覆盖面积 |
| ExterQual: | 外观材质 |
| ExterCond | 外墙材料的现状 |
| Foundation | 地基类型 |
| BsmtQual | 地下室的高度 |
| BsmtCond | 地下室概况 |
| BsmtExposure: | 走道或花园式地下室墙 |
| BsmtFinType1 | 地下室竣工面积质量 |
| BsmtFinSF1 | 1型成品面积 |
| BsmtFinType2 | 第二成品区域的质量(如果存在) |
| BsmtFinSF2 | 2型成品面积 |
| BsmtUnfSF | 地下室面积 |
| TotalBsmtSF | 地下室面积总计面积 |
| Heating | 暖气方式 |
| HeatingQC | 暖气质量与条件 |
| CentralAir | 空调 |
| Electrical | 电气系统 |
| 1stFlrSF | 一楼面积 |
| 2ndFlrSF | 二楼面积 |
| LowQualFinSF | 低质量完工面积(所有楼层) |
| GrLivArea | 高档(地面)居住面积 |
| BsmtFullBath | 地下室全浴室 |
| BsmtHalfBath | 地下室半浴室 |
| FullBath | 高档浴室 |
| HalfBath | 半日以上洗澡浴室 |
| Bedroom | 地下室层以上的卧室数 |
| Kitchen | 厨房数量 |
| KitchenQual | 厨房品质 |
| TotRmsAbvGrd | 总房间(不包括浴室) |
| Functional | 家庭功能评级 |
| Fireplaces | 壁炉数 |
| FireplaceQu | 壁炉质量 |
| GarageType | 车库位置 |
| GarageYrBlt | 车库建成年 |
| GarageFinish | 车库的内饰 |
| GarageCars | 车库容量大小 |
| GarageArea | 车库大小 |
| GarageQual | 车库质量 |
| GarageCond | 车库状况 |
| PavedDrive | 铺好的车道 |
| WoodDeckSF | 木制甲板面积 |
| OpenPorchSF | 外部走廊面积 |
| EnclosedPorch | 闭走廊面积 |
| 3SsnPorch: | 三季走廊面积 |
| ScreenPorch | 屏风走廊面积 |
| PoolArea | 泳池面积 |
| PoolQC | 泳池的质量 |
| Fence | 围栏质量 |
| MiscFeature | 其他类别的杂项特征 |
| MiscVal | 杂项价值 |
| MoSold | 月售出 |
| YrSold | 年销售 |
| SaleType | 销售类型 |
| SaleCondition | 销售条件 |
把这些数据整理成Excel表格。发现很多东西看不明白。