image_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

train_data = pd.read_csv('../input/house-prices-advanced-regression-techniques/train.csv')
test_data = pd.read_csv('../input/house-prices-advanced-regression-techniques/test.csv')

train_data.shape

test_data.shape

fig = plt.figure(figsize=(10,5))
sns.distplot(train_data['SalePrice'])
plt.tight_layout()
plt.show()

fig = plt.figure(figsize=(10,5))
sns.distplot(np.log1p(train_data['SalePrice']))
plt.tight_layout()
plt.show()

cat_data = train_data.select_dtypes(include='object')
cat_cols = cat_data.columns
num_data = train_data.select_dtypes(exclude='object')
num_cols = num_data.columns
num_to_cat_cols = ['MSSubClass', 'MoSold', 'YrSold', 'OverallQual', 'OverallCond']
num_cols = [i for i in num_cols if not i in num_to_cat_cols]
num_cols = [i for i in num_cols if not i in ['Id']]
num_data = num_data.drop(['Id', 'MSSubClass', 'MoSold', 'YrSold', 'OverallQual', 'OverallCond'], axis=1)

for i in range(len(cat_data.columns)):
    f, ax = plt.subplots(figsize=(7, 4))
    fig = sns.countplot(cat_data.iloc[:,i].dropna())
    plt.xlabel(cat_data.columns[i])
    plt.xticks(rotation=60)

for i in range(len(num_data.columns)):
    f, ax = plt.subplots(figsize=(7, 4))
    fig = sns.distplot(num_data.iloc[:,i].dropna(), rug=False, hist=False, kde_kws={'bw':0.1})
    plt.xlabel(num_data.columns[i])

skew_dict = {}
for cols in num_cols:
    skew_dict[cols] = {'Skewness': train_data[cols].skew()}
skew_df = pd.DataFrame(skew_dict).transpose()
skew_df.columns = ['Skewness']
skew_df.sort_values(by=['Skewness'], ascending=False)

fig = plt.figure(figsize=(12,18))
for i in range(len(num_data.columns)):
    fig.add_subplot(9, 4, i+1)
    sns.scatterplot(num_data.iloc[:, i], num_data['SalePrice'])
plt.tight_layout()
plt.show()

corr_matrix = train_data[num_cols].corr()
corr_matrix['SalePrice'].sort_values(ascending=False)

train_data = train_data.drop(train_data[train_data['Id'] == 524].index)
train_data = train_data.drop(train_data[train_data['Id'] == 1299].index)

model_data = pd.concat([train_data, test_data], axis=0, sort=None, ignore_index=True)

sns.lmplot('Age', 'SalePrice', data=model_data, height=8)
plt.title('Age vs SalePrice')
plt.show()