加州房价预测

本文使用加利福尼亚州房价数据集进行分析,包括数据加载、探索、特征分析、重要特征提取、数据清洗、训练线性回归模型并评估,以及对比不同模型的性能。通过对数据的深入探究,发现中位收入可能是预测房价的最重要因素。
摘要由CSDN通过智能技术生成

California Housing

I select California Housing dataset for data analysis.

Part 1 Load Datasets

I download California Housing dataset from https://www.kaggle.com/camnugent/california-housing-prices and save it as housing.csv.

Then,I load it.

from sklearn import datasets
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import Imputer
import numpy as np
housing_data = pd.read_csv('housing.csv')

Then,split train data and test data

from sklearn.model_selection import train_test_split
train_set, test_set = train_test_split(housing_data, test_size=0.2, random_state=42)

Part 2 Explore the dataset

I explore the dataset using the histogram.

First,we need to copy the train data

housing = train_set.copy()

start to explore the dataset

housing.hist(bins=50,figsize=(20,15))
plt.show()

在这里插入图片描述
From the picture we can see all the features.

Part 3 Analyse the dataset

I display data through visualization using matplotlib.
Let’s look at the impact of longitude and latitude on house prices.

plt.scatter(x = housing['longitude'],y = housing['latitude'],alpha = 0.1)
plt.show()

在这里插入图片描述
Let’s see other features.

housing.plot(kind="scatter",x="longitude",y="latitude",alpha=0.4,
             s=housing["population"]/100,label="population",
             c="median_house_value",cmap=plt.get_cmap("jet"),colorbar=True,sharex=False)

plt.legend()
plt.show()

在这里插入图片描述

Part 4 Extract the important features

Let’s look at correlation between each pair of feature.

corr_matrix = housing.corr()
print(corr_matrix['median_house_value'].sort_values(ascending = False))
median_house_value    1.000000
median_income         0.688075
total_rooms       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值