房价分析--墨尔本

本文通过对kaggle上的墨尔本房价数据进行分析,包括数据预处理、特征理解,如房间数分布、异常值处理、价格估算等。使用总价除以房间数得到粗略的定价策略,并发现房间数与平均价格的关系。通过箱线图揭示不同房屋类型的中位价差异。此外,区域位置和与CBD的距离对房价影响显著。最后,进行了线性回归预测,结果显示模型预测值偏高。
摘要由CSDN通过智能技术生成

*数据来自kaggle

1、认识数据

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
house_prices=pd.read_csv('E:\DESK\house_prices.csv',engine='python')
house_prices.head()   #查看前5行
Out[125]: 
         Suburb             ...                             CouncilArea
0    Abbotsford             ...                      Yarra City Council
1    Abbotsford             ...                      Yarra City Council
2    Abbotsford             ...                      Yarra City Council
3    Aberfeldie             ...              Moonee Valley City Council
4  Airport West             ...              Moonee Valley City Council

[5 rows x 13 columns]
house_prices.describe()          #展示数据的一些基础信息
Out[126]:   
              Rooms         Price      ...       Propertycount      Distance
count  63023.000000  4.843300e+04      ...        63023.000000  63023.000000
mean       3.110595  9.978982e+05      ...         7617.728131     12.684829
std        0.957551  5.934989e+05      ...         4424.423167      7.592015
min        1.000000  8.500000e+04      ...           39.000000      0.000000
25%        3.000000  6.200000e+05      ...         4380.000000      7.000000
50%        3.000000  8.300000e+05      ...         6795.000000     11.400000
75%        4.000000  1.220000e+06      ...        10412.000000     16.700000
max       31.000000  1.120000e+07      ...        21650.000000     64.100000

[8 rows x 5 columns]
house_prices.info()    #展示了每列数据的个数、空值类型及数据类型
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 63023 entries, 0 to 63022
Data columns (total 13 columns):
Suburb           63023 non-null object
Address          63023 non-null object
Rooms            63023 non-null int64
Type             63023 non-null object
Price            48433 non-null float64
Method           63023 non-null object
SellerG          63023 non-null object
Date             63023 non-null object
Postcode         63023 non-null int64
Regionname       63023 non-null object
Propertycount    63023 non-null int64
Distance         63023 non-null float64
CouncilArea      63023 non-null object
dtypes: float64(2), int64(3), object(8)
memory usage: 6.3+ MB

2、数据整理

house_prices.isnull().sum()      #计算每列值的空值个数    
Out[128]: 
Suburb               0
Address              0
Rooms                0
Type                 0
Price            14590
Method               0
SellerG              0
Date                 0
Postcode             0
Regionname           0
Propertycount        0
Distance             0
CouncilArea          0
dtype: int64

house_prices.dropna(how='any',inplace=True)  #删除有空值的行

可看出数据中仅Price数据存在空值,将含有空值的行删除。

3、认识数据

  • Rooms列数据有多个值,从下图可看出,房间数多分布在1-5之间。
g = sns.kdeplot(house_prices.Rooms, color="Red", shade = True)
g.set_xlabel("Rooms")
g.set_ylabel("Frequency")
plt.title('Distribution of Rooms',size = 20)



  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值