房屋价格预测

编程入门 行业动态 更新时间:2024-10-06 10:28:06

<a href=https://www.elefans.com/category/jswz/34/1762711.html style=房屋价格预测"/>

房屋价格预测

房屋价格预测-数据分析(python)

dataset download(.html#assignment-1)

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from IPython import display
display.set_matplotlib_formats('svg')data = pd.read_feather('house_sales.ftr')
# data = pd.read_csv('house_sales.zip')
# print(data.shape)
# print(data.head)null_sum = data.isnull().sum()
print(data.columns[null_sum < len(data) * 0.3])
data.drop(columns=data.columns[null_sum > len(data) * 0.3], inplace=True)print(data.dtypes)currency = ['Sold Price', 'Listed Price', 'Tax assessed value', 'Annual tax amount']
for c in currency:data[c] = data[c].replace(r'[$,-]', '', regex=True).replace(r'^\s*$', np.nan, regex=True).astype(float)areas = ['Total interior livable area', 'Lot size']
for c in areas:acres = data[c].str.contains('Acres') == Truecol = data[c].replace(r'\b sqft\b|\b Acres\b|\b,\b', '', regex=True).astype(float)col[acres] *= 43560data[c] = colprint(data.describe())# simple handle, handle the too small or too big data
abnormal = (data[areas[1]] < 10) | (data[areas[1]] > 1e4)
data = data[~abnormal]
print('abnormal: ', sum(abnormal))# ax = sns.histplot(np.log10(data['Sold Price']))
# ax.set_xlim([3, 8])
# ax.set_xticks(range(3, 9))
# ax.set_xticklabels(['%.0e'%a for a in 10**ax.get_xticks()])
# plt.show()print(data['Type'].value_counts()[0:20])types = data['Type'].isin(['SingleFamily', 'Condo', 'MultiFamily', 'Townhouse'])
# sns.displot(pd.DataFrame({
#     'Sold Price': np.log10(data[types]['Sold Price']),
#     'Type': data[types]['Type']
# }), x='Sold Price', hue='Type', kind='kde')
# plt.show()data['Price per living sqft'] = data['Sold Price'] / data['Total interior livable area']
ax = sns.boxplot(x='Type', y='Price per living sqft', data=data[types], fliersize=0)
ax.set_ylim([0, 2000])
# plt.show()d = data[data['Zip'].isin(data['Zip'].value_counts()[:20].keys())]
ax = sns.boxplot(x='Zip', y='Price per living sqft', data=d, fliersize=0)
ax.set_ylim([0, 2000])
ax.set_xticklabels(ax.get_xticklabels(), rotation=90)
# plt.show()_, ax = plt.subplots(figsize=(6, 6))
columns = ['Sold Price', 'Listed Price', 'Annual tax amount', 'Price per living sqft']
sns.heatmap(data[columns].corr(), annot=True, cmap='RdYlGn', ax=ax)
plt.show()





更多推荐

房屋价格预测

本文发布于:2024-02-14 09:16:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1762685.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:房屋   价格

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!