text_plain_output_1.png
from scipy.stats import skew

from sklearn.linear_model import LinearRegression

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)

total = merged_dataset.isnull().sum().sort_values(ascending=False)
percent = (merged_dataset.isnull().sum() / merged_dataset.isnull().count()).sort_values(ascending=False)
missing_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])

corrmat = merged_dataset.corr()['SalePrice']
corrmat = corrmat.sort_values(axis=0, ascending=False)
corrmat[corrmat > 0.5]

merged_dataset.select_dtypes(include=['int64', 'float64']).columns
merged_dataset['Alley'].fillna('None', inplace=True)
merged_dataset['BsmtQual'].fillna(value='None', inplace=True)
merged_dataset['BsmtCond'].fillna(value='None', inplace=True)
merged_dataset['BsmtExposure'].fillna(value='None', inplace=True)
merged_dataset['BsmtFinType1'].fillna(value='None', inplace=True)
merged_dataset['BsmtFinType2'].fillna(value='None', inplace=True)
merged_dataset['BsmtFinSF1'].fillna(value=0, inplace=True)
merged_dataset['BsmtFinSF2'].fillna(value=0, inplace=True)
merged_dataset['BsmtFullBath'].fillna(value=0, inplace=True)
merged_dataset['BsmtHalfBath'].fillna(value=0, inplace=True)
merged_dataset['BsmtUnfSF'].fillna(value=0, inplace=True)
merged_dataset['TotalBsmtSF'].fillna(value=0, inplace=True)
merged_dataset['Electrical'].fillna(value='SBrkr', inplace=True)
merged_dataset['FireplaceQu'].fillna(value='None', inplace=True)
merged_dataset['GarageType'].fillna(value='None', inplace=True)
merged_dataset['GarageYrBlt'].fillna(value='None', inplace=True)
merged_dataset['GarageFinish'].fillna(value='None', inplace=True)
merged_dataset['GarageQual'].fillna(value='None', inplace=True)
merged_dataset['GarageCond'].fillna(value='None', inplace=True)
merged_dataset['GarageArea'].fillna(value=0, inplace=True)
merged_dataset['GarageCars'].fillna(value=0, inplace=True)
merged_dataset['PoolQC'].fillna(value='None', inplace=True)
merged_dataset['LotFrontage'].fillna(value=0, inplace=True)
merged_dataset['MiscFeature'].fillna(value='None', inplace=True)
merged_dataset['Exterior1st'].fillna(value='None', inplace=True)
merged_dataset['Exterior2nd'].fillna(value='None', inplace=True)
merged_dataset['Functional'].fillna(value='None', inplace=True)
merged_dataset['KitchenQual'].fillna(value='None', inplace=True)
merged_dataset['MSZoning'].fillna(value='None', inplace=True)
merged_dataset['SaleType'].fillna(value='None', inplace=True)
merged_dataset['Utilities'].fillna(value='None', inplace=True)
merged_dataset['MasVnrType'].fillna(value='None', inplace=True)
merged_dataset['MasVnrArea'].fillna(value=0, inplace=True)
merged_dataset['Fence'].fillna(value='None', inplace=True)

merged_dataset['SalePrice'] = np.log1p(merged_dataset['SalePrice'])
numeric_feats = merged_dataset.dtypes[merged_dataset.dtypes != 'object'].index
skewed_feats = merged_dataset[numeric_feats].apply(lambda x: skew(x.dropna()))
skewed_feats = skewed_feats[skewed_feats > 0.75]
skewed_feats = skewed_feats.index
merged_dataset[skewed_feats] = np.log1p(merged_dataset[skewed_feats])

new_train = merged_dataset[:1460]
X_train = new_train.drop('SalePrice', axis=1)
y_train = new_train['SalePrice']

new_test = merged_dataset[1460:]
X_test = new_test.drop('SalePrice', axis=1)

lr = LinearRegression().fit(X_train, y_train)
prediction = np.expm1(lr.predict(X_test))
print(prediction)