text_plain_output_1.png
from sklearn.preprocessing import LabelEncoder

import numpy as np # linear algebra

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

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

from sklearn.preprocessing import LabelEncoder
train_data['MSZoning'] = LabelEncoder().fit_transform(train_data['MSZoning'])
train_data['Street'] = LabelEncoder().fit_transform(train_data['Street'])
train_data['Alley'] = train_data['Alley'].fillna('Not')
train_data['Alley'] = LabelEncoder().fit_transform(train_data['Alley'])
train_data['LotShape'] = LabelEncoder().fit_transform(train_data['LotShape'])
train_data['LandContour'] = LabelEncoder().fit_transform(train_data['LandContour'])
train_data['Utilities'] = LabelEncoder().fit_transform(train_data['Utilities'])
train_data['LotConfig'] = LabelEncoder().fit_transform(train_data['LotConfig'])
train_data['LandSlope'] = LabelEncoder().fit_transform(train_data['LandSlope'])
train_data['Neighborhood'] = LabelEncoder().fit_transform(train_data['Neighborhood'])
train_data['Condition1'] = LabelEncoder().fit_transform(train_data['Condition1'])
train_data['Condition2'] = LabelEncoder().fit_transform(train_data['Condition2'])
train_data['BldgType'] = LabelEncoder().fit_transform(train_data['BldgType'])
train_data['HouseStyle'] = LabelEncoder().fit_transform(train_data['HouseStyle'])
train_data['RoofStyle'] = LabelEncoder().fit_transform(train_data['RoofStyle'])
train_data['RoofMatl'] = LabelEncoder().fit_transform(train_data['RoofMatl'])
train_data['Exterior1st'] = LabelEncoder().fit_transform(train_data['Exterior1st'])
train_data['Exterior2nd'] = LabelEncoder().fit_transform(train_data['Exterior2nd'])
train_data['MasVnrType'] = train_data['MasVnrType'].fillna('Not')
train_data['MasVnrType'] = LabelEncoder().fit_transform(train_data['MasVnrType'])
train_data['ExterQual'] = LabelEncoder().fit_transform(train_data['ExterQual'])
train_data['ExterCond'] = LabelEncoder().fit_transform(train_data['ExterCond'])
train_data['Foundation'] = LabelEncoder().fit_transform(train_data['Foundation'])
train_data['BsmtQual'] = train_data['BsmtQual'].fillna('Not')
train_data['BsmtQual'] = LabelEncoder().fit_transform(train_data['BsmtQual'])
train_data['BsmtCond'] = train_data['BsmtCond'].fillna('Not')
train_data['BsmtCond'] = LabelEncoder().fit_transform(train_data['BsmtCond'])
train_data['BsmtExposure'] = train_data['BsmtExposure'].fillna('Not')
train_data['BsmtExposure'] = LabelEncoder().fit_transform(train_data['BsmtExposure'])
train_data['BsmtFinType1'] = train_data['BsmtFinType1'].fillna('Not')
train_data['BsmtFinType1'] = LabelEncoder().fit_transform(train_data['BsmtFinType1'])
train_data['BsmtFinType2'] = train_data['BsmtFinType2'].fillna('Not')
train_data['BsmtFinType2'] = LabelEncoder().fit_transform(train_data['BsmtFinType2'])
train_data['Heating'] = LabelEncoder().fit_transform(train_data['Heating'])
train_data['HeatingQC'] = LabelEncoder().fit_transform(train_data['HeatingQC'])
train_data['CentralAir'] = LabelEncoder().fit_transform(train_data['CentralAir'])
train_data['Electrical'] = train_data['Electrical'].fillna('SBrkr')
train_data['Electrical'] = LabelEncoder().fit_transform(train_data['Electrical'])
train_data['KitchenQual'] = LabelEncoder().fit_transform(train_data['KitchenQual'])
train_data['Functional'] = LabelEncoder().fit_transform(train_data['Functional'])
train_data['FireplaceQu'] = train_data['FireplaceQu'].fillna('Not')
train_data['FireplaceQu'] = LabelEncoder().fit_transform(train_data['FireplaceQu'])
train_data['GarageType'] = train_data['GarageType'].fillna('Not')
train_data['GarageType'] = LabelEncoder().fit_transform(train_data['GarageType'])
train_data['GarageFinish'] = train_data['GarageFinish'].fillna('Not')
train_data['GarageFinish'] = LabelEncoder().fit_transform(train_data['GarageFinish'])
train_data['GarageQual'] = train_data['GarageQual'].fillna('Not')
train_data['GarageQual'] = LabelEncoder().fit_transform(train_data['GarageQual'])
train_data['GarageCond'] = train_data['GarageCond'].fillna('Not')
train_data['GarageCond'] = LabelEncoder().fit_transform(train_data['GarageCond'])
train_data['PavedDrive'] = LabelEncoder().fit_transform(train_data['PavedDrive'])
train_data['PoolQC'] = train_data['PoolQC'].fillna('Not')
train_data['PoolQC'] = LabelEncoder().fit_transform(train_data['PoolQC'])
train_data['Fence'] = train_data['Fence'].fillna('Not')
train_data['Fence'] = LabelEncoder().fit_transform(train_data['Fence'])
train_data['MiscFeature'] = train_data['MiscFeature'].fillna('Not')
train_data['MiscFeature'] = LabelEncoder().fit_transform(train_data['MiscFeature'])
train_data['SaleType'] = LabelEncoder().fit_transform(train_data['SaleType'])
train_data['SaleCondition'] = LabelEncoder().fit_transform(train_data['SaleCondition'])
train_data['LotFrontage'] = train_data['LotFrontage'].fillna(np.mean(train_data['LotFrontage']))
train_data['MasVnrArea'] = train_data['MasVnrArea'].fillna(np.mean(train_data['MasVnrArea']))
train_data['GarageYrBlt'] = train_data['GarageYrBlt'].fillna(np.mean(train_data['GarageYrBlt']))

test_data['Street'] = LabelEncoder().fit_transform(test_data['Street'])
test_data['Alley'] = test_data['Alley'].fillna('Not')
test_data['Alley'] = LabelEncoder().fit_transform(test_data['Alley'])
test_data['LotShape'] = LabelEncoder().fit_transform(test_data['LotShape'])
test_data['LandContour'] = LabelEncoder().fit_transform(test_data['LandContour'])
test_data['LotConfig'] = LabelEncoder().fit_transform(test_data['LotConfig'])
test_data['LandSlope'] = LabelEncoder().fit_transform(test_data['LandSlope'])
test_data['Neighborhood'] = LabelEncoder().fit_transform(test_data['Neighborhood'])
test_data['Condition1'] = LabelEncoder().fit_transform(test_data['Condition1'])
test_data['Condition2'] = LabelEncoder().fit_transform(test_data['Condition2'])
test_data['BldgType'] = LabelEncoder().fit_transform(test_data['BldgType'])
test_data['HouseStyle'] = LabelEncoder().fit_transform(test_data['HouseStyle'])
test_data['RoofStyle'] = LabelEncoder().fit_transform(test_data['RoofStyle'])
test_data['RoofMatl'] = LabelEncoder().fit_transform(test_data['RoofMatl'])
test_data['MasVnrType'] = test_data['MasVnrType'].fillna('Not')
test_data['MasVnrType'] = LabelEncoder().fit_transform(test_data['MasVnrType'])
test_data['ExterQual'] = LabelEncoder().fit_transform(test_data['ExterQual'])
test_data['ExterCond'] = LabelEncoder().fit_transform(test_data['ExterCond'])
test_data['Foundation'] = LabelEncoder().fit_transform(test_data['Foundation'])
test_data['BsmtQual'] = test_data['BsmtQual'].fillna('Not')
test_data['BsmtQual'] = LabelEncoder().fit_transform(test_data['BsmtQual'])
test_data['BsmtCond'] = test_data['BsmtCond'].fillna('Not')
test_data['BsmtCond'] = LabelEncoder().fit_transform(test_data['BsmtCond'])
test_data['BsmtExposure'] = test_data['BsmtExposure'].fillna('Not')
test_data['BsmtExposure'] = LabelEncoder().fit_transform(test_data['BsmtExposure'])
test_data['BsmtFinType1'] = test_data['BsmtFinType1'].fillna('Not')
test_data['BsmtFinType1'] = LabelEncoder().fit_transform(test_data['BsmtFinType1'])
test_data['BsmtFinType2'] = test_data['BsmtFinType2'].fillna('Not')
test_data['BsmtFinType2'] = LabelEncoder().fit_transform(test_data['BsmtFinType2'])
test_data['Heating'] = LabelEncoder().fit_transform(test_data['Heating'])
test_data['HeatingQC'] = LabelEncoder().fit_transform(test_data['HeatingQC'])
test_data['CentralAir'] = LabelEncoder().fit_transform(test_data['CentralAir'])
test_data['Electrical'] = test_data['Electrical'].fillna('SBrkr')
test_data['Electrical'] = LabelEncoder().fit_transform(test_data['Electrical'])
test_data['FireplaceQu'] = test_data['FireplaceQu'].fillna('Not')
test_data['FireplaceQu'] = LabelEncoder().fit_transform(test_data['FireplaceQu'])
test_data['GarageType'] = test_data['GarageType'].fillna('Not')
test_data['GarageType'] = LabelEncoder().fit_transform(test_data['GarageType'])
test_data['GarageFinish'] = test_data['GarageFinish'].fillna('Not')
test_data['GarageFinish'] = LabelEncoder().fit_transform(test_data['GarageFinish'])
test_data['GarageQual'] = test_data['GarageQual'].fillna('Not')
test_data['GarageQual'] = LabelEncoder().fit_transform(test_data['GarageQual'])
test_data['GarageCond'] = test_data['GarageCond'].fillna('Not')
test_data['GarageCond'] = LabelEncoder().fit_transform(test_data['GarageCond'])
test_data['PavedDrive'] = LabelEncoder().fit_transform(test_data['PavedDrive'])
test_data['PoolQC'] = test_data['PoolQC'].fillna('Not')
test_data['PoolQC'] = LabelEncoder().fit_transform(test_data['PoolQC'])
test_data['Fence'] = test_data['Fence'].fillna('Not')
test_data['Fence'] = LabelEncoder().fit_transform(test_data['Fence'])
test_data['MiscFeature'] = test_data['MiscFeature'].fillna('Not')
test_data['MiscFeature'] = LabelEncoder().fit_transform(test_data['MiscFeature'])
test_data['SaleCondition'] = LabelEncoder().fit_transform(test_data['SaleCondition'])
test_data['LotFrontage'] = test_data['LotFrontage'].fillna(np.mean(test_data['LotFrontage']))
test_data['MasVnrArea'] = test_data['MasVnrArea'].fillna(np.mean(test_data['MasVnrArea']))
test_data['GarageYrBlt'] = test_data['GarageYrBlt'].fillna(np.mean(test_data['GarageYrBlt']))
print(test_data.head(10))