text_plain_output_1.png
from scipy import stats

from sklearn.linear_model import LinearRegression

import matplotlib.pyplot as plt

import numpy as np

import numpy as np # linear algebra

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

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

fig = plt.figure()
res = stats.probplot(df_train['SalePrice'], plot=plt)
plt.show()

df_train["SalePrice"] = np.log1p(df_train["SalePrice"])

fig = plt.figure()
res = stats.probplot(df_train['SalePrice'], plot=plt)
plt.show()

y_train = df_train['SalePrice']

df = pd.concat((df_train, df_test)).reset_index(drop=True)
df = df.drop(['Id', 'SalePrice'], axis=1)

df_1 = df.copy()
for feature in ['PoolQC', 'MiscFeature', 'Alley', 'Fence', 'FireplaceQu', 'GarageType', 'GarageFinish', 'GarageQual', 'GarageCond', 'BsmtQual', 'BsmtCond', 'BsmtExposure', 'BsmtFinType1', 'BsmtFinType2', 'MasVnrType', 'MSSubClass']:
    df_1[feature] = df_1[feature].fillna('None')

df_2 = df_1.copy()
for feature in ['GarageYrBlt', 'GarageArea', 'GarageCars', 'BsmtFinSF1', 'BsmtFinSF2', 'BsmtUnfSF', 'TotalBsmtSF', 'BsmtFullBath', 'BsmtHalfBath', 'MasVnrArea']:
    df_2[feature] = df_2[feature].fillna(0)

df_3 = df_2.copy()
for feature in ['MSZoning', 'Electrical', 'KitchenQual', 'Exterior1st', 'Exterior2nd', 'SaleType']:
    df_3[feature] = df_3[feature].fillna(df_3[feature].mode()[0])

df_4 = df_3.copy()
df_4['Functional'] = df_4['Functional'].fillna('Typ')

df_5 = df_4.copy()
df_5 = df_5.drop(['Utilities'], axis=1)

df_6 = df_5.copy()
df_6['LotFrontage'] = df_6.groupby('Neighborhood')['LotFrontage'].transform(lambda x: x.fillna(x.median()))

df_7 = df_6.copy()
df_7 = pd.get_dummies(df_7)

df_8 = df_7.copy()
numerical_features = df_8.dtypes[df_8.dtypes != 'object'].index

df_train = df_8[:df_train.shape[0]]
df_test = df_8[df_train.shape[0]:]

lr = LinearRegression()
lr.fit(df_train, y_train)

y_pred = lr.predict(df_test)
y_pred