{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-08T11:46:13.423286Z","iopub.execute_input":"2022-07-08T11:46:13.423830Z","iopub.status.idle":"2022-07-08T11:46:13.464953Z","shell.execute_reply.started":"2022-07-08T11:46:13.423723Z","shell.execute_reply":"2022-07-08T11:46:13.463842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# reading the data\ntrain_df = pd.read_csv(\"../input/house-prices-advanced-regression-techniques/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:13.467918Z","iopub.execute_input":"2022-07-08T11:46:13.468388Z","iopub.status.idle":"2022-07-08T11:46:13.518526Z","shell.execute_reply.started":"2022-07-08T11:46:13.468345Z","shell.execute_reply":"2022-07-08T11:46:13.517603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:13.523733Z","iopub.execute_input":"2022-07-08T11:46:13.524425Z","iopub.status.idle":"2022-07-08T11:46:13.569736Z","shell.execute_reply.started":"2022-07-08T11:46:13.524372Z","shell.execute_reply":"2022-07-08T11:46:13.568545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\nsns.countplot(x = 'MSSubClass',data = train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:13.608201Z","iopub.execute_input":"2022-07-08T11:46:13.608972Z","iopub.status.idle":"2022-07-08T11:46:14.596650Z","shell.execute_reply.started":"2022-07-08T11:46:13.608916Z","shell.execute_reply":"2022-07-08T11:46:14.595124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(x = 'MSSubClass',y='SalePrice',data = train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:14.598619Z","iopub.execute_input":"2022-07-08T11:46:14.599007Z","iopub.status.idle":"2022-07-08T11:46:14.846696Z","shell.execute_reply.started":"2022-07-08T11:46:14.598974Z","shell.execute_reply":"2022-07-08T11:46:14.845085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"from above plots we can say that 1 & 2 story of year 1946 and after have been in great demand compared to others.","metadata":{}},{"cell_type":"code","source":"sns.scatterplot(x='LotFrontage',y='SalePrice',data = train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:14.848556Z","iopub.execute_input":"2022-07-08T11:46:14.849016Z","iopub.status.idle":"2022-07-08T11:46:15.082319Z","shell.execute_reply.started":"2022-07-08T11:46:14.848981Z","shell.execute_reply":"2022-07-08T11:46:15.081165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of the house sold have lot frontage less than 150","metadata":{}},{"cell_type":"code","source":"sns.scatterplot(x='LotArea',y='SalePrice',data = train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:15.085145Z","iopub.execute_input":"2022-07-08T11:46:15.086239Z","iopub.status.idle":"2022-07-08T11:46:15.310211Z","shell.execute_reply.started":"2022-07-08T11:46:15.086189Z","shell.execute_reply":"2022-07-08T11:46:15.308804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of house sold has lot area less than 30000 square feet","metadata":{}},{"cell_type":"code","source":"sns.countplot(x='Street',data= train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:15.311937Z","iopub.execute_input":"2022-07-08T11:46:15.312351Z","iopub.status.idle":"2022-07-08T11:46:15.510499Z","shell.execute_reply.started":"2022-07-08T11:46:15.312316Z","shell.execute_reply":"2022-07-08T11:46:15.509627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"almost all houses have Paved street.So it doesnt affect so much on our price. Therfore we can conveniently drop the \"Street\" column","metadata":{}},{"cell_type":"code","source":"train_df.drop('Street',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:15.511769Z","iopub.execute_input":"2022-07-08T11:46:15.512258Z","iopub.status.idle":"2022-07-08T11:46:15.519106Z","shell.execute_reply.started":"2022-07-08T11:46:15.512225Z","shell.execute_reply":"2022-07-08T11:46:15.517753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:15.520676Z","iopub.execute_input":"2022-07-08T11:46:15.521479Z","iopub.status.idle":"2022-07-08T11:46:15.554669Z","shell.execute_reply.started":"2022-07-08T11:46:15.521434Z","shell.execute_reply":"2022-07-08T11:46:15.553564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"From above info we see that columns like 'Alley','PoolQC' and 'MiscFeature' have lot of missing values.Let us drop them from our data.","metadata":{}},{"cell_type":"code","source":"train_df.drop(['Alley','PoolQC','MiscFeature'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:15.557504Z","iopub.execute_input":"2022-07-08T11:46:15.557878Z","iopub.status.idle":"2022-07-08T11:46:15.566675Z","shell.execute_reply.started":"2022-07-08T11:46:15.557846Z","shell.execute_reply":"2022-07-08T11:46:15.565190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize =(15,8))\nsns.heatmap(train_df.isnull(),yticklabels = False,cbar=False,cmap='viridis')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:15.568148Z","iopub.execute_input":"2022-07-08T11:46:15.568466Z","iopub.status.idle":"2022-07-08T11:46:16.868728Z","shell.execute_reply.started":"2022-07-08T11:46:15.568438Z","shell.execute_reply":"2022-07-08T11:46:16.867613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.transpose(train_df.describe())","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:16.870756Z","iopub.execute_input":"2022-07-08T11:46:16.871618Z","iopub.status.idle":"2022-07-08T11:46:17.012330Z","shell.execute_reply.started":"2022-07-08T11:46:16.871545Z","shell.execute_reply":"2022-07-08T11:46:17.010903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#we will fill the misising values in LotFrontage by the mean of other values in that column\n#which is 70 (from describe() method above).Also most of the houses sold have LotFrontage \n#less than 150 so it is fair enough to fill missing value with mean\ntrain_df['LotFrontage'] = train_df['LotFrontage'].fillna(value=70)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:17.014101Z","iopub.execute_input":"2022-07-08T11:46:17.014558Z","iopub.status.idle":"2022-07-08T11:46:17.022006Z","shell.execute_reply.started":"2022-07-08T11:46:17.014514Z","shell.execute_reply":"2022-07-08T11:46:17.020514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(x='LotArea',y = 'SalePrice',data=train_df,hue=\"LotShape\")","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:17.024084Z","iopub.execute_input":"2022-07-08T11:46:17.024647Z","iopub.status.idle":"2022-07-08T11:46:17.389401Z","shell.execute_reply.started":"2022-07-08T11:46:17.024573Z","shell.execute_reply":"2022-07-08T11:46:17.388241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(x='LotArea',y = 'SalePrice',data=train_df,hue=\"LotConfig\")","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:17.390865Z","iopub.execute_input":"2022-07-08T11:46:17.391450Z","iopub.status.idle":"2022-07-08T11:46:17.763393Z","shell.execute_reply.started":"2022-07-08T11:46:17.391414Z","shell.execute_reply":"2022-07-08T11:46:17.762173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='Utilities',data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:17.764994Z","iopub.execute_input":"2022-07-08T11:46:17.765401Z","iopub.status.idle":"2022-07-08T11:46:17.940064Z","shell.execute_reply.started":"2022-07-08T11:46:17.765368Z","shell.execute_reply":"2022-07-08T11:46:17.939213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"From above countplot we can say that all houses have all public utilities. So it is better to drop the Utilities column.","metadata":{}},{"cell_type":"code","source":"train_df.drop('Utilities',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:17.941398Z","iopub.execute_input":"2022-07-08T11:46:17.942061Z","iopub.status.idle":"2022-07-08T11:46:17.950110Z","shell.execute_reply.started":"2022-07-08T11:46:17.942021Z","shell.execute_reply":"2022-07-08T11:46:17.949205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='LotConfig',data=train_df,hue='LotShape')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:17.951268Z","iopub.execute_input":"2022-07-08T11:46:17.952256Z","iopub.status.idle":"2022-07-08T11:46:18.215928Z","shell.execute_reply.started":"2022-07-08T11:46:17.952220Z","shell.execute_reply":"2022-07-08T11:46:18.214780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='LandContour',data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:18.217373Z","iopub.execute_input":"2022-07-08T11:46:18.217739Z","iopub.status.idle":"2022-07-08T11:46:18.345335Z","shell.execute_reply.started":"2022-07-08T11:46:18.217706Z","shell.execute_reply":"2022-07-08T11:46:18.344146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='Condition2',data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:18.348169Z","iopub.execute_input":"2022-07-08T11:46:18.348661Z","iopub.status.idle":"2022-07-08T11:46:18.507739Z","shell.execute_reply.started":"2022-07-08T11:46:18.348615Z","shell.execute_reply":"2022-07-08T11:46:18.506408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# As majority of houses have Condition2 as normal it is safe to drop this column\ntrain_df.drop('Condition2',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:18.515296Z","iopub.execute_input":"2022-07-08T11:46:18.515688Z","iopub.status.idle":"2022-07-08T11:46:18.522506Z","shell.execute_reply.started":"2022-07-08T11:46:18.515655Z","shell.execute_reply":"2022-07-08T11:46:18.521391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='LandSlope',data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:18.524240Z","iopub.execute_input":"2022-07-08T11:46:18.525004Z","iopub.status.idle":"2022-07-08T11:46:18.651407Z","shell.execute_reply.started":"2022-07-08T11:46:18.524959Z","shell.execute_reply":"2022-07-08T11:46:18.650253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# it is safe to drop LandSlope column as well\ntrain_df.drop('LandSlope',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:18.653156Z","iopub.execute_input":"2022-07-08T11:46:18.654922Z","iopub.status.idle":"2022-07-08T11:46:18.662675Z","shell.execute_reply.started":"2022-07-08T11:46:18.654871Z","shell.execute_reply":"2022-07-08T11:46:18.661532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='BldgType',data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:18.664449Z","iopub.execute_input":"2022-07-08T11:46:18.664895Z","iopub.status.idle":"2022-07-08T11:46:18.858394Z","shell.execute_reply.started":"2022-07-08T11:46:18.664852Z","shell.execute_reply":"2022-07-08T11:46:18.856251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='HouseStyle',data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:18.860723Z","iopub.execute_input":"2022-07-08T11:46:18.861893Z","iopub.status.idle":"2022-07-08T11:46:19.212671Z","shell.execute_reply.started":"2022-07-08T11:46:18.861840Z","shell.execute_reply":"2022-07-08T11:46:19.211457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='OverallQual',y='OverallCond',data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:19.214118Z","iopub.execute_input":"2022-07-08T11:46:19.214449Z","iopub.status.idle":"2022-07-08T11:46:19.706230Z","shell.execute_reply.started":"2022-07-08T11:46:19.214418Z","shell.execute_reply":"2022-07-08T11:46:19.705060Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='RoofStyle',data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:19.707691Z","iopub.execute_input":"2022-07-08T11:46:19.708131Z","iopub.status.idle":"2022-07-08T11:46:19.894092Z","shell.execute_reply.started":"2022-07-08T11:46:19.708099Z","shell.execute_reply":"2022-07-08T11:46:19.893282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='RoofMatl',data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:19.895487Z","iopub.execute_input":"2022-07-08T11:46:19.896515Z","iopub.status.idle":"2022-07-08T11:46:20.103632Z","shell.execute_reply.started":"2022-07-08T11:46:19.896479Z","shell.execute_reply":"2022-07-08T11:46:20.102523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# we will drop RoofMatl column\ntrain_df.drop('RoofMatl',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:20.104953Z","iopub.execute_input":"2022-07-08T11:46:20.105249Z","iopub.status.idle":"2022-07-08T11:46:20.111605Z","shell.execute_reply.started":"2022-07-08T11:46:20.105222Z","shell.execute_reply":"2022-07-08T11:46:20.110534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# we will consider Exterior2nd and drop Exterior1st\ntrain_df.drop('Exterior1st',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:20.112818Z","iopub.execute_input":"2022-07-08T11:46:20.113333Z","iopub.status.idle":"2022-07-08T11:46:20.126134Z","shell.execute_reply.started":"2022-07-08T11:46:20.113283Z","shell.execute_reply":"2022-07-08T11:46:20.125259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# In all cases we will consider present conditions of house and drop the quality columns\ntrain_df.drop(['ExterQual','BsmtQual','GarageQual'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:20.127332Z","iopub.execute_input":"2022-07-08T11:46:20.128294Z","iopub.status.idle":"2022-07-08T11:46:20.138086Z","shell.execute_reply.started":"2022-07-08T11:46:20.128252Z","shell.execute_reply":"2022-07-08T11:46:20.137150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:20.139242Z","iopub.execute_input":"2022-07-08T11:46:20.140006Z","iopub.status.idle":"2022-07-08T11:46:20.169068Z","shell.execute_reply.started":"2022-07-08T11:46:20.139974Z","shell.execute_reply":"2022-07-08T11:46:20.168160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,8))\nsns.heatmap(train_df.isnull(),yticklabels=False,cbar=False,cmap='viridis')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:20.170269Z","iopub.execute_input":"2022-07-08T11:46:20.170826Z","iopub.status.idle":"2022-07-08T11:46:21.378908Z","shell.execute_reply.started":"2022-07-08T11:46:20.170794Z","shell.execute_reply":"2022-07-08T11:46:21.377635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"we will fill NaN values in \"FireplaceQu\" and 'Fence' as \"No\" because for that houses there is no fireplace and fence","metadata":{}},{"cell_type":"code","source":"train_df[['Fence','FireplaceQu']]=train_df[['Fence','FireplaceQu']].fillna(value = \"No\")","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:21.380682Z","iopub.execute_input":"2022-07-08T11:46:21.381336Z","iopub.status.idle":"2022-07-08T11:46:21.399103Z","shell.execute_reply.started":"2022-07-08T11:46:21.381287Z","shell.execute_reply":"2022-07-08T11:46:21.396090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Let us come to garage sections now\ntrain_df[['GarageType','GarageYrBlt','GarageFinish','GarageCars','GarageArea','GarageCond']].head()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:21.401787Z","iopub.execute_input":"2022-07-08T11:46:21.402654Z","iopub.status.idle":"2022-07-08T11:46:21.430317Z","shell.execute_reply.started":"2022-07-08T11:46:21.402572Z","shell.execute_reply":"2022-07-08T11:46:21.429321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(x='YearBuilt',y='GarageYrBlt',data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:21.431673Z","iopub.execute_input":"2022-07-08T11:46:21.432232Z","iopub.status.idle":"2022-07-08T11:46:21.657821Z","shell.execute_reply.started":"2022-07-08T11:46:21.432198Z","shell.execute_reply":"2022-07-08T11:46:21.656311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(x='YearRemodAdd',y='GarageYrBlt', data = train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:21.659730Z","iopub.execute_input":"2022-07-08T11:46:21.660064Z","iopub.status.idle":"2022-07-08T11:46:21.874683Z","shell.execute_reply.started":"2022-07-08T11:46:21.660035Z","shell.execute_reply":"2022-07-08T11:46:21.873353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#From above we see that GarageYrBlt and house year built are highly linearly correlated.\n#It is safe to drop the GarageYrBLt column","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:21.876247Z","iopub.execute_input":"2022-07-08T11:46:21.876952Z","iopub.status.idle":"2022-07-08T11:46:21.882270Z","shell.execute_reply.started":"2022-07-08T11:46:21.876914Z","shell.execute_reply":"2022-07-08T11:46:21.880915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.drop('GarageYrBlt',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:21.884159Z","iopub.execute_input":"2022-07-08T11:46:21.885051Z","iopub.status.idle":"2022-07-08T11:46:21.897033Z","shell.execute_reply.started":"2022-07-08T11:46:21.884901Z","shell.execute_reply":"2022-07-08T11:46:21.895675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# we see that there are some NaN values in garage columns. let us fill it wil 'No' \n# garage does not exisit in those homes","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:21.899398Z","iopub.execute_input":"2022-07-08T11:46:21.900149Z","iopub.status.idle":"2022-07-08T11:46:21.909339Z","shell.execute_reply.started":"2022-07-08T11:46:21.900065Z","shell.execute_reply":"2022-07-08T11:46:21.908283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df[['GarageType','GarageFinish','GarageCond']]=train_df[['GarageType','GarageFinish','GarageCond']].fillna(value = 'No')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:21.911512Z","iopub.execute_input":"2022-07-08T11:46:21.912396Z","iopub.status.idle":"2022-07-08T11:46:21.931036Z","shell.execute_reply.started":"2022-07-08T11:46:21.912346Z","shell.execute_reply":"2022-07-08T11:46:21.929526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,8))\nsns.heatmap(train_df.isnull(),yticklabels=False,cbar=False,cmap='viridis')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:21.932982Z","iopub.execute_input":"2022-07-08T11:46:21.933917Z","iopub.status.idle":"2022-07-08T11:46:23.094739Z","shell.execute_reply.started":"2022-07-08T11:46:21.933869Z","shell.execute_reply":"2022-07-08T11:46:23.093523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Let us now focus on basement\n# we will drop columns like BsmtExposure,BsmntType1,BsmtType2,BsmtUnfSF\n","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:23.096661Z","iopub.execute_input":"2022-07-08T11:46:23.097151Z","iopub.status.idle":"2022-07-08T11:46:23.102160Z","shell.execute_reply.started":"2022-07-08T11:46:23.097104Z","shell.execute_reply":"2022-07-08T11:46:23.100886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.drop(['BsmtExposure','BsmtFinType1','BsmtFinType2','BsmtUnfSF'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:23.103543Z","iopub.execute_input":"2022-07-08T11:46:23.103921Z","iopub.status.idle":"2022-07-08T11:46:23.118344Z","shell.execute_reply.started":"2022-07-08T11:46:23.103890Z","shell.execute_reply":"2022-07-08T11:46:23.117366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:23.119777Z","iopub.execute_input":"2022-07-08T11:46:23.120126Z","iopub.status.idle":"2022-07-08T11:46:23.150503Z","shell.execute_reply.started":"2022-07-08T11:46:23.120096Z","shell.execute_reply":"2022-07-08T11:46:23.148741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# we will fill missing values in basement as 'No' as those houses dont have basment\ntrain_df['BsmtCond'] =train_df['BsmtCond'].fillna('No')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:23.152153Z","iopub.execute_input":"2022-07-08T11:46:23.152882Z","iopub.status.idle":"2022-07-08T11:46:23.161244Z","shell.execute_reply.started":"2022-07-08T11:46:23.152832Z","shell.execute_reply":"2022-07-08T11:46:23.159759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,8))\nsns.heatmap(train_df.isnull(),yticklabels=False,cbar=False,cmap='viridis')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:23.162624Z","iopub.execute_input":"2022-07-08T11:46:23.163146Z","iopub.status.idle":"2022-07-08T11:46:24.260264Z","shell.execute_reply.started":"2022-07-08T11:46:23.163102Z","shell.execute_reply":"2022-07-08T11:46:24.258982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.dropna(inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.261917Z","iopub.execute_input":"2022-07-08T11:46:24.262681Z","iopub.status.idle":"2022-07-08T11:46:24.278204Z","shell.execute_reply.started":"2022-07-08T11:46:24.262636Z","shell.execute_reply":"2022-07-08T11:46:24.276877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# now we have cleaned data.\n#Let us convert categories into dummy variables","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.280086Z","iopub.execute_input":"2022-07-08T11:46:24.280433Z","iopub.status.idle":"2022-07-08T11:46:24.286337Z","shell.execute_reply.started":"2022-07-08T11:46:24.280392Z","shell.execute_reply":"2022-07-08T11:46:24.285061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.287888Z","iopub.execute_input":"2022-07-08T11:46:24.288882Z","iopub.status.idle":"2022-07-08T11:46:24.299556Z","shell.execute_reply.started":"2022-07-08T11:46:24.288835Z","shell.execute_reply":"2022-07-08T11:46:24.298396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mszone = pd.get_dummies(train_df['MSZoning'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.301555Z","iopub.execute_input":"2022-07-08T11:46:24.302015Z","iopub.status.idle":"2022-07-08T11:46:24.311625Z","shell.execute_reply.started":"2022-07-08T11:46:24.301972Z","shell.execute_reply":"2022-07-08T11:46:24.310729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lot_shape = pd.get_dummies(train_df['LotShape'],drop_first=True)\nland_contour = pd.get_dummies(train_df['LandContour'],drop_first=True)\nlot_config = pd.get_dummies(train_df['LotConfig'],drop_first=True)\nneighbor = pd.get_dummies(train_df['Neighborhood'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.313051Z","iopub.execute_input":"2022-07-08T11:46:24.313525Z","iopub.status.idle":"2022-07-08T11:46:24.327549Z","shell.execute_reply.started":"2022-07-08T11:46:24.313490Z","shell.execute_reply":"2022-07-08T11:46:24.326452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cond = pd.get_dummies(train_df['Condition1'],drop_first=True)\nbldg = pd.get_dummies(train_df['BldgType'],drop_first=True)\nhousestyle = pd.get_dummies(train_df['HouseStyle'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.329079Z","iopub.execute_input":"2022-07-08T11:46:24.329398Z","iopub.status.idle":"2022-07-08T11:46:24.340048Z","shell.execute_reply.started":"2022-07-08T11:46:24.329369Z","shell.execute_reply":"2022-07-08T11:46:24.338820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"roofstyle = pd.get_dummies(train_df['RoofStyle'],drop_first = True)\next2 = pd.get_dummies(train_df['Exterior2nd'],drop_first=True)\nmason = pd.get_dummies(train_df['MasVnrType'],drop_first=True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.355051Z","iopub.execute_input":"2022-07-08T11:46:24.355461Z","iopub.status.idle":"2022-07-08T11:46:24.367344Z","shell.execute_reply.started":"2022-07-08T11:46:24.355426Z","shell.execute_reply":"2022-07-08T11:46:24.366376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ext_cond = pd.get_dummies(train_df['ExterCond'],drop_first=True)\nfound = pd.get_dummies(train_df['Foundation'],drop_first=True)\nbase = pd.get_dummies(train_df['BsmtCond'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.369649Z","iopub.execute_input":"2022-07-08T11:46:24.370769Z","iopub.status.idle":"2022-07-08T11:46:24.379935Z","shell.execute_reply.started":"2022-07-08T11:46:24.370733Z","shell.execute_reply":"2022-07-08T11:46:24.378885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"heat = pd.get_dummies(train_df['HeatingQC'],drop_first=True)\ncent_air = pd.get_dummies(train_df['CentralAir'],drop_first=True)\nelect  = pd.get_dummies(train_df['Electrical'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.381600Z","iopub.execute_input":"2022-07-08T11:46:24.382354Z","iopub.status.idle":"2022-07-08T11:46:24.391607Z","shell.execute_reply.started":"2022-07-08T11:46:24.382219Z","shell.execute_reply":"2022-07-08T11:46:24.390540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kit = pd.get_dummies(train_df['KitchenQual'],drop_first=True)\nfunc = pd.get_dummies(train_df['Functional'],drop_first=True)\nfire = pd.get_dummies(train_df['FireplaceQu'],drop_first=True)\ngarage_type = pd.get_dummies(train_df['GarageType'],drop_first=True)\ngarage_cond = pd.get_dummies(train_df['GarageCond'],drop_first=True)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.393511Z","iopub.execute_input":"2022-07-08T11:46:24.394248Z","iopub.status.idle":"2022-07-08T11:46:24.409387Z","shell.execute_reply.started":"2022-07-08T11:46:24.394202Z","shell.execute_reply":"2022-07-08T11:46:24.408191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='PavedDrive',data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.411050Z","iopub.execute_input":"2022-07-08T11:46:24.411866Z","iopub.status.idle":"2022-07-08T11:46:24.580307Z","shell.execute_reply.started":"2022-07-08T11:46:24.411831Z","shell.execute_reply":"2022-07-08T11:46:24.578955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pave = pd.get_dummies(train_df['PavedDrive'],drop_first=True)\nfence = pd.get_dummies(train_df['Fence'],drop_first=True)\nsaletype = pd.get_dummies(train_df['SaleType'],drop_first=True)\nsalecon = pd.get_dummies(train_df['SaleCondition'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.582072Z","iopub.execute_input":"2022-07-08T11:46:24.583032Z","iopub.status.idle":"2022-07-08T11:46:24.594949Z","shell.execute_reply.started":"2022-07-08T11:46:24.582985Z","shell.execute_reply":"2022-07-08T11:46:24.593790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.concat([train_df,mszone,lot_shape,land_contour,lot_config,neighbor,\n                     cond,bldg,housestyle,roofstyle,ext2,mason,ext_cond,found,base,\n                     heat,cent_air,elect,kit,func,fire,garage_type,garage_cond,\n                     pave,fence,saletype,salecon],axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.596466Z","iopub.execute_input":"2022-07-08T11:46:24.596816Z","iopub.status.idle":"2022-07-08T11:46:24.611694Z","shell.execute_reply.started":"2022-07-08T11:46:24.596785Z","shell.execute_reply":"2022-07-08T11:46:24.610670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.613385Z","iopub.execute_input":"2022-07-08T11:46:24.613774Z","iopub.status.idle":"2022-07-08T11:46:24.640572Z","shell.execute_reply.started":"2022-07-08T11:46:24.613741Z","shell.execute_reply":"2022-07-08T11:46:24.639551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.drop(['MSZoning','LotShape','LandContour','LotConfig','Neighborhood',\n              'Condition1','BldgType','HouseStyle','RoofStyle', 'Exterior2nd', 'MasVnrType',\n              'ExterCond', 'Foundation', 'BsmtCond','Heating','HeatingQC','CentralAir','Electrical',\n              'KitchenQual','Functional','FireplaceQu', 'GarageType', 'GarageFinish','GarageCond','PavedDrive',\n               'Fence','SaleType','SaleCondition'], axis=1,inplace=True)\n              ","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.642527Z","iopub.execute_input":"2022-07-08T11:46:24.642905Z","iopub.status.idle":"2022-07-08T11:46:24.656892Z","shell.execute_reply.started":"2022-07-08T11:46:24.642872Z","shell.execute_reply":"2022-07-08T11:46:24.654924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.658218Z","iopub.execute_input":"2022-07-08T11:46:24.658782Z","iopub.status.idle":"2022-07-08T11:46:24.684098Z","shell.execute_reply.started":"2022-07-08T11:46:24.658746Z","shell.execute_reply":"2022-07-08T11:46:24.682905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.685424Z","iopub.execute_input":"2022-07-08T11:46:24.685767Z","iopub.status.idle":"2022-07-08T11:46:24.705861Z","shell.execute_reply.started":"2022-07-08T11:46:24.685737Z","shell.execute_reply":"2022-07-08T11:46:24.704154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Now our training data is free of object datatypes.Let us split it and build Linear Regression model","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.707328Z","iopub.execute_input":"2022-07-08T11:46:24.707705Z","iopub.status.idle":"2022-07-08T11:46:24.712875Z","shell.execute_reply.started":"2022-07-08T11:46:24.707672Z","shell.execute_reply":"2022-07-08T11:46:24.711598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = train_df.drop(['SalePrice','2.5Fin','Mix','Other'],axis=1)\ny = train_df['SalePrice']","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.714506Z","iopub.execute_input":"2022-07-08T11:46:24.715912Z","iopub.status.idle":"2022-07-08T11:46:24.732189Z","shell.execute_reply.started":"2022-07-08T11:46:24.715862Z","shell.execute_reply":"2022-07-08T11:46:24.731218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.733807Z","iopub.execute_input":"2022-07-08T11:46:24.734982Z","iopub.status.idle":"2022-07-08T11:46:24.760135Z","shell.execute_reply.started":"2022-07-08T11:46:24.734907Z","shell.execute_reply":"2022-07-08T11:46:24.759125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.761757Z","iopub.execute_input":"2022-07-08T11:46:24.762632Z","iopub.status.idle":"2022-07-08T11:46:24.900556Z","shell.execute_reply.started":"2022-07-08T11:46:24.762555Z","shell.execute_reply":"2022-07-08T11:46:24.898894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=101)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.902209Z","iopub.execute_input":"2022-07-08T11:46:24.904842Z","iopub.status.idle":"2022-07-08T11:46:24.914877Z","shell.execute_reply.started":"2022-07-08T11:46:24.904802Z","shell.execute_reply":"2022-07-08T11:46:24.913647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LinearRegression","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:24.919361Z","iopub.execute_input":"2022-07-08T11:46:24.920258Z","iopub.status.idle":"2022-07-08T11:46:25.008940Z","shell.execute_reply.started":"2022-07-08T11:46:24.920213Z","shell.execute_reply":"2022-07-08T11:46:25.007772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lm = LinearRegression()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.010616Z","iopub.execute_input":"2022-07-08T11:46:25.011286Z","iopub.status.idle":"2022-07-08T11:46:25.017040Z","shell.execute_reply.started":"2022-07-08T11:46:25.011238Z","shell.execute_reply":"2022-07-08T11:46:25.015919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lm.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.018569Z","iopub.execute_input":"2022-07-08T11:46:25.018928Z","iopub.status.idle":"2022-07-08T11:46:25.091511Z","shell.execute_reply.started":"2022-07-08T11:46:25.018899Z","shell.execute_reply":"2022-07-08T11:46:25.090164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lm.coef_","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.098152Z","iopub.execute_input":"2022-07-08T11:46:25.099095Z","iopub.status.idle":"2022-07-08T11:46:25.122267Z","shell.execute_reply.started":"2022-07-08T11:46:25.099036Z","shell.execute_reply":"2022-07-08T11:46:25.120916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cdf = pd.DataFrame(lm.coef_,X.columns,columns=['Coeff'])","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.129264Z","iopub.execute_input":"2022-07-08T11:46:25.130863Z","iopub.status.idle":"2022-07-08T11:46:25.139447Z","shell.execute_reply.started":"2022-07-08T11:46:25.130795Z","shell.execute_reply":"2022-07-08T11:46:25.138151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cdf","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.141870Z","iopub.execute_input":"2022-07-08T11:46:25.142844Z","iopub.status.idle":"2022-07-08T11:46:25.166594Z","shell.execute_reply.started":"2022-07-08T11:46:25.142788Z","shell.execute_reply":"2022-07-08T11:46:25.165320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lm.intercept_","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.168817Z","iopub.execute_input":"2022-07-08T11:46:25.169783Z","iopub.status.idle":"2022-07-08T11:46:25.178341Z","shell.execute_reply.started":"2022-07-08T11:46:25.169729Z","shell.execute_reply":"2022-07-08T11:46:25.177121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lm_predictions = lm.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.180572Z","iopub.execute_input":"2022-07-08T11:46:25.181530Z","iopub.status.idle":"2022-07-08T11:46:25.196781Z","shell.execute_reply.started":"2022-07-08T11:46:25.181475Z","shell.execute_reply":"2022-07-08T11:46:25.195423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import mean_absolute_error,mean_squared_error","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.199419Z","iopub.execute_input":"2022-07-08T11:46:25.200430Z","iopub.status.idle":"2022-07-08T11:46:25.208534Z","shell.execute_reply.started":"2022-07-08T11:46:25.200374Z","shell.execute_reply":"2022-07-08T11:46:25.207031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lm_mae = mean_absolute_error(y_test,lm_predictions)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.211950Z","iopub.execute_input":"2022-07-08T11:46:25.212976Z","iopub.status.idle":"2022-07-08T11:46:25.228682Z","shell.execute_reply.started":"2022-07-08T11:46:25.212926Z","shell.execute_reply":"2022-07-08T11:46:25.227279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lm_mae","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.232265Z","iopub.execute_input":"2022-07-08T11:46:25.234149Z","iopub.status.idle":"2022-07-08T11:46:25.249311Z","shell.execute_reply.started":"2022-07-08T11:46:25.234054Z","shell.execute_reply":"2022-07-08T11:46:25.247691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lm_mse = mean_squared_error(y_test,lm_predictions)\nlm_mse","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.252174Z","iopub.execute_input":"2022-07-08T11:46:25.253512Z","iopub.status.idle":"2022-07-08T11:46:25.271743Z","shell.execute_reply.started":"2022-07-08T11:46:25.253455Z","shell.execute_reply":"2022-07-08T11:46:25.270418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lm_rmse = np.sqrt(lm_mse)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.274353Z","iopub.execute_input":"2022-07-08T11:46:25.276954Z","iopub.status.idle":"2022-07-08T11:46:25.291710Z","shell.execute_reply.started":"2022-07-08T11:46:25.276895Z","shell.execute_reply":"2022-07-08T11:46:25.290299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lm_rmse","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.294131Z","iopub.execute_input":"2022-07-08T11:46:25.295291Z","iopub.status.idle":"2022-07-08T11:46:25.309035Z","shell.execute_reply.started":"2022-07-08T11:46:25.295236Z","shell.execute_reply":"2022-07-08T11:46:25.307543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn import metrics\nlm_r2 = metrics.r2_score(y_test,lm_predictions)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.311511Z","iopub.execute_input":"2022-07-08T11:46:25.312645Z","iopub.status.idle":"2022-07-08T11:46:25.319836Z","shell.execute_reply.started":"2022-07-08T11:46:25.312555Z","shell.execute_reply":"2022-07-08T11:46:25.318679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lm_r2","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.321792Z","iopub.execute_input":"2022-07-08T11:46:25.322617Z","iopub.status.idle":"2022-07-08T11:46:25.338620Z","shell.execute_reply.started":"2022-07-08T11:46:25.322543Z","shell.execute_reply":"2022-07-08T11:46:25.337308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\nplt.scatter(y_test,lm_predictions)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.340791Z","iopub.execute_input":"2022-07-08T11:46:25.341563Z","iopub.status.idle":"2022-07-08T11:46:25.564823Z","shell.execute_reply.started":"2022-07-08T11:46:25.341516Z","shell.execute_reply":"2022-07-08T11:46:25.563650Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# For Linear Regression model we are getting r2_score as 0.77 which is not so bad. Let us now try Random Forest Regressor ","metadata":{"execution":{"iopub.status.busy":"2022-07-07T11:58:27.865811Z","iopub.execute_input":"2022-07-07T11:58:27.866944Z","iopub.status.idle":"2022-07-07T11:58:27.887341Z","shell.execute_reply.started":"2022-07-07T11:58:27.866903Z","shell.execute_reply":"2022-07-07T11:58:27.886528Z"}}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestRegressor","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.566384Z","iopub.execute_input":"2022-07-08T11:46:25.566823Z","iopub.status.idle":"2022-07-08T11:46:25.728306Z","shell.execute_reply.started":"2022-07-08T11:46:25.566789Z","shell.execute_reply":"2022-07-08T11:46:25.727202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rfr = RandomForestRegressor(n_estimators=180)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.729761Z","iopub.execute_input":"2022-07-08T11:46:25.730200Z","iopub.status.idle":"2022-07-08T11:46:25.735565Z","shell.execute_reply.started":"2022-07-08T11:46:25.730157Z","shell.execute_reply":"2022-07-08T11:46:25.734354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rfr.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:25.737709Z","iopub.execute_input":"2022-07-08T11:46:25.738284Z","iopub.status.idle":"2022-07-08T11:46:28.965840Z","shell.execute_reply.started":"2022-07-08T11:46:25.738234Z","shell.execute_reply":"2022-07-08T11:46:28.964404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rfr_predictions = rfr.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:28.967341Z","iopub.execute_input":"2022-07-08T11:46:28.967734Z","iopub.status.idle":"2022-07-08T11:46:29.018710Z","shell.execute_reply.started":"2022-07-08T11:46:28.967702Z","shell.execute_reply":"2022-07-08T11:46:29.017506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\nplt.scatter(y_test, rfr_predictions)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.020035Z","iopub.execute_input":"2022-07-08T11:46:29.020343Z","iopub.status.idle":"2022-07-08T11:46:29.181836Z","shell.execute_reply.started":"2022-07-08T11:46:29.020316Z","shell.execute_reply":"2022-07-08T11:46:29.180542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rfr_mae = metrics.mean_absolute_error(y_test,rfr_predictions)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.183481Z","iopub.execute_input":"2022-07-08T11:46:29.183858Z","iopub.status.idle":"2022-07-08T11:46:29.191255Z","shell.execute_reply.started":"2022-07-08T11:46:29.183829Z","shell.execute_reply":"2022-07-08T11:46:29.189226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rfr_mae","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.193022Z","iopub.execute_input":"2022-07-08T11:46:29.194124Z","iopub.status.idle":"2022-07-08T11:46:29.205628Z","shell.execute_reply.started":"2022-07-08T11:46:29.194071Z","shell.execute_reply":"2022-07-08T11:46:29.204348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rfr_mse = metrics.mean_squared_error(y_test,rfr_predictions)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.208162Z","iopub.execute_input":"2022-07-08T11:46:29.209385Z","iopub.status.idle":"2022-07-08T11:46:29.219493Z","shell.execute_reply.started":"2022-07-08T11:46:29.209345Z","shell.execute_reply":"2022-07-08T11:46:29.218102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rfr_mse","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.221361Z","iopub.execute_input":"2022-07-08T11:46:29.221868Z","iopub.status.idle":"2022-07-08T11:46:29.237451Z","shell.execute_reply.started":"2022-07-08T11:46:29.221822Z","shell.execute_reply":"2022-07-08T11:46:29.235759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rfr_rmse = np.sqrt(rfr_mse)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.239424Z","iopub.execute_input":"2022-07-08T11:46:29.239841Z","iopub.status.idle":"2022-07-08T11:46:29.249935Z","shell.execute_reply.started":"2022-07-08T11:46:29.239806Z","shell.execute_reply":"2022-07-08T11:46:29.248677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rfr_rmse","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.251457Z","iopub.execute_input":"2022-07-08T11:46:29.251947Z","iopub.status.idle":"2022-07-08T11:46:29.266992Z","shell.execute_reply.started":"2022-07-08T11:46:29.251904Z","shell.execute_reply":"2022-07-08T11:46:29.266063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rfr_r2 = metrics.r2_score(y_test,rfr_predictions)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.268189Z","iopub.execute_input":"2022-07-08T11:46:29.269181Z","iopub.status.idle":"2022-07-08T11:46:29.279484Z","shell.execute_reply.started":"2022-07-08T11:46:29.269143Z","shell.execute_reply":"2022-07-08T11:46:29.278489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rfr_r2","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.280986Z","iopub.execute_input":"2022-07-08T11:46:29.281348Z","iopub.status.idle":"2022-07-08T11:46:29.294742Z","shell.execute_reply.started":"2022-07-08T11:46:29.281316Z","shell.execute_reply":"2022-07-08T11:46:29.293021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Random Forest Regressor model gives r2 score of 0.855","metadata":{}},{"cell_type":"code","source":"#Now let us predict with both our model on test data\ntest_df = pd.read_csv(\"../input/house-prices-advanced-regression-techniques/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.296905Z","iopub.execute_input":"2022-07-08T11:46:29.298131Z","iopub.status.idle":"2022-07-08T11:46:29.346494Z","shell.execute_reply.started":"2022-07-08T11:46:29.298068Z","shell.execute_reply":"2022-07-08T11:46:29.344987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.347983Z","iopub.execute_input":"2022-07-08T11:46:29.348547Z","iopub.status.idle":"2022-07-08T11:46:29.376910Z","shell.execute_reply.started":"2022-07-08T11:46:29.348511Z","shell.execute_reply":"2022-07-08T11:46:29.375669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.378455Z","iopub.execute_input":"2022-07-08T11:46:29.378802Z","iopub.status.idle":"2022-07-08T11:46:29.404867Z","shell.execute_reply.started":"2022-07-08T11:46:29.378771Z","shell.execute_reply":"2022-07-08T11:46:29.403965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.transpose(test_df.describe())","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.405832Z","iopub.execute_input":"2022-07-08T11:46:29.406144Z","iopub.status.idle":"2022-07-08T11:46:29.529061Z","shell.execute_reply.started":"2022-07-08T11:46:29.406114Z","shell.execute_reply":"2022-07-08T11:46:29.527664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# we will follow the same steps as we did for our training data","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.530790Z","iopub.execute_input":"2022-07-08T11:46:29.531324Z","iopub.status.idle":"2022-07-08T11:46:29.537889Z","shell.execute_reply.started":"2022-07-08T11:46:29.531280Z","shell.execute_reply":"2022-07-08T11:46:29.536567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.drop(['Street','Alley','PoolQC','MiscFeature'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.541462Z","iopub.execute_input":"2022-07-08T11:46:29.541816Z","iopub.status.idle":"2022-07-08T11:46:29.551754Z","shell.execute_reply.started":"2022-07-08T11:46:29.541786Z","shell.execute_reply":"2022-07-08T11:46:29.550682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['LotFrontage'] = train_df['LotFrontage'].fillna(value=68.5)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.554641Z","iopub.execute_input":"2022-07-08T11:46:29.555386Z","iopub.status.idle":"2022-07-08T11:46:29.566466Z","shell.execute_reply.started":"2022-07-08T11:46:29.555337Z","shell.execute_reply":"2022-07-08T11:46:29.565592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.drop(['Utilities','Condition2'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.568233Z","iopub.execute_input":"2022-07-08T11:46:29.568542Z","iopub.status.idle":"2022-07-08T11:46:29.581317Z","shell.execute_reply.started":"2022-07-08T11:46:29.568515Z","shell.execute_reply":"2022-07-08T11:46:29.579805Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.drop(['LandSlope','RoofMatl','Exterior1st','ExterQual','BsmtQual','GarageQual'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.583254Z","iopub.execute_input":"2022-07-08T11:46:29.583791Z","iopub.status.idle":"2022-07-08T11:46:29.597999Z","shell.execute_reply.started":"2022-07-08T11:46:29.583731Z","shell.execute_reply":"2022-07-08T11:46:29.596948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df[['Fence','FireplaceQu']]=test_df[['Fence','FireplaceQu']].fillna(value = \"No\")","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.598994Z","iopub.execute_input":"2022-07-08T11:46:29.599332Z","iopub.status.idle":"2022-07-08T11:46:29.611941Z","shell.execute_reply.started":"2022-07-08T11:46:29.599301Z","shell.execute_reply":"2022-07-08T11:46:29.610620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df[['GarageType','GarageFinish','GarageCond']]=test_df[['GarageType','GarageFinish','GarageCond']].fillna(value = 'No')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.614241Z","iopub.execute_input":"2022-07-08T11:46:29.615202Z","iopub.status.idle":"2022-07-08T11:46:29.624890Z","shell.execute_reply.started":"2022-07-08T11:46:29.615153Z","shell.execute_reply":"2022-07-08T11:46:29.623799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.drop('GarageYrBlt',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.626538Z","iopub.execute_input":"2022-07-08T11:46:29.626910Z","iopub.status.idle":"2022-07-08T11:46:29.638956Z","shell.execute_reply.started":"2022-07-08T11:46:29.626876Z","shell.execute_reply":"2022-07-08T11:46:29.637475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.drop(['BsmtExposure','BsmtFinType1','BsmtFinType2','BsmtUnfSF'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.640573Z","iopub.execute_input":"2022-07-08T11:46:29.641427Z","iopub.status.idle":"2022-07-08T11:46:29.652213Z","shell.execute_reply.started":"2022-07-08T11:46:29.641386Z","shell.execute_reply":"2022-07-08T11:46:29.650895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['BsmtCond'] =test_df['BsmtCond'].fillna('No')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.653273Z","iopub.execute_input":"2022-07-08T11:46:29.653658Z","iopub.status.idle":"2022-07-08T11:46:29.662306Z","shell.execute_reply.started":"2022-07-08T11:46:29.653617Z","shell.execute_reply":"2022-07-08T11:46:29.661194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,8))\nsns.heatmap(test_df.isnull(),yticklabels=False, cbar=False, cmap='viridis')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:29.663678Z","iopub.execute_input":"2022-07-08T11:46:29.664174Z","iopub.status.idle":"2022-07-08T11:46:30.711227Z","shell.execute_reply.started":"2022-07-08T11:46:29.664144Z","shell.execute_reply":"2022-07-08T11:46:30.709767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['LotFrontage'] = test_df['LotFrontage'].fillna(value=68.5)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:30.713503Z","iopub.execute_input":"2022-07-08T11:46:30.714020Z","iopub.status.idle":"2022-07-08T11:46:30.721649Z","shell.execute_reply.started":"2022-07-08T11:46:30.713974Z","shell.execute_reply":"2022-07-08T11:46:30.720336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['LotFrontage'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:30.723696Z","iopub.execute_input":"2022-07-08T11:46:30.724530Z","iopub.status.idle":"2022-07-08T11:46:30.735365Z","shell.execute_reply.started":"2022-07-08T11:46:30.724486Z","shell.execute_reply":"2022-07-08T11:46:30.734163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['MasVnrType'] = test_df['MasVnrType'].fillna(value = 'None')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:30.738926Z","iopub.execute_input":"2022-07-08T11:46:30.739270Z","iopub.status.idle":"2022-07-08T11:46:30.747179Z","shell.execute_reply.started":"2022-07-08T11:46:30.739239Z","shell.execute_reply":"2022-07-08T11:46:30.746234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['MasVnrType'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:30.748349Z","iopub.execute_input":"2022-07-08T11:46:30.749599Z","iopub.status.idle":"2022-07-08T11:46:30.762192Z","shell.execute_reply.started":"2022-07-08T11:46:30.749473Z","shell.execute_reply":"2022-07-08T11:46:30.761024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['MasVnrArea'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:30.764002Z","iopub.execute_input":"2022-07-08T11:46:30.764325Z","iopub.status.idle":"2022-07-08T11:46:30.772869Z","shell.execute_reply.started":"2022-07-08T11:46:30.764296Z","shell.execute_reply":"2022-07-08T11:46:30.771666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['MasVnrArea']=test_df['MasVnrArea'].fillna(value=0)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:30.774479Z","iopub.execute_input":"2022-07-08T11:46:30.774995Z","iopub.status.idle":"2022-07-08T11:46:30.782384Z","shell.execute_reply.started":"2022-07-08T11:46:30.774960Z","shell.execute_reply":"2022-07-08T11:46:30.781010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['KitchenQual'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:30.785691Z","iopub.execute_input":"2022-07-08T11:46:30.786666Z","iopub.status.idle":"2022-07-08T11:46:30.799119Z","shell.execute_reply.started":"2022-07-08T11:46:30.786626Z","shell.execute_reply":"2022-07-08T11:46:30.797372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['KitchenQual']=test_df['KitchenQual'].fillna(value = 'TA')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:30.800706Z","iopub.execute_input":"2022-07-08T11:46:30.802076Z","iopub.status.idle":"2022-07-08T11:46:30.811735Z","shell.execute_reply.started":"2022-07-08T11:46:30.802019Z","shell.execute_reply":"2022-07-08T11:46:30.810684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,8))\nsns.heatmap(test_df.isnull(),yticklabels=False, cbar=False, cmap='viridis')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:30.813431Z","iopub.execute_input":"2022-07-08T11:46:30.813859Z","iopub.status.idle":"2022-07-08T11:46:32.034180Z","shell.execute_reply.started":"2022-07-08T11:46:30.813825Z","shell.execute_reply":"2022-07-08T11:46:32.032817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.035869Z","iopub.execute_input":"2022-07-08T11:46:32.036436Z","iopub.status.idle":"2022-07-08T11:46:32.062878Z","shell.execute_reply.started":"2022-07-08T11:46:32.036387Z","shell.execute_reply":"2022-07-08T11:46:32.061611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Now we will convert categories into dummy variables","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.064471Z","iopub.execute_input":"2022-07-08T11:46:32.065724Z","iopub.status.idle":"2022-07-08T11:46:32.070691Z","shell.execute_reply.started":"2022-07-08T11:46:32.065686Z","shell.execute_reply":"2022-07-08T11:46:32.069479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_mszone = pd.get_dummies(test_df['MSZoning'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.072409Z","iopub.execute_input":"2022-07-08T11:46:32.073140Z","iopub.status.idle":"2022-07-08T11:46:32.086181Z","shell.execute_reply.started":"2022-07-08T11:46:32.073101Z","shell.execute_reply":"2022-07-08T11:46:32.084843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_lot_shape = pd.get_dummies(test_df['LotShape'],drop_first=True)\ntest_land_contour = pd.get_dummies(test_df['LandContour'],drop_first=True)\ntest_lot_config = pd.get_dummies(test_df['LotConfig'],drop_first=True)\ntest_neighbor = pd.get_dummies(test_df['Neighborhood'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.088637Z","iopub.execute_input":"2022-07-08T11:46:32.089535Z","iopub.status.idle":"2022-07-08T11:46:32.104179Z","shell.execute_reply.started":"2022-07-08T11:46:32.089434Z","shell.execute_reply":"2022-07-08T11:46:32.102690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_cond = pd.get_dummies(test_df['Condition1'],drop_first=True)\ntest_bldg = pd.get_dummies(test_df['BldgType'],drop_first=True)\ntest_housestyle = pd.get_dummies(test_df['HouseStyle'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.105707Z","iopub.execute_input":"2022-07-08T11:46:32.106399Z","iopub.status.idle":"2022-07-08T11:46:32.117971Z","shell.execute_reply.started":"2022-07-08T11:46:32.106360Z","shell.execute_reply":"2022-07-08T11:46:32.116531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_roofstyle = pd.get_dummies(test_df['RoofStyle'],drop_first = True)\ntest_ext2 = pd.get_dummies(test_df['Exterior2nd'],drop_first=True)\ntest_mason = pd.get_dummies(test_df['MasVnrType'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.120047Z","iopub.execute_input":"2022-07-08T11:46:32.121079Z","iopub.status.idle":"2022-07-08T11:46:32.134972Z","shell.execute_reply.started":"2022-07-08T11:46:32.121035Z","shell.execute_reply":"2022-07-08T11:46:32.133324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_ext_cond = pd.get_dummies(test_df['ExterCond'],drop_first=True)\ntest_found = pd.get_dummies(test_df['Foundation'],drop_first=True)\ntest_base = pd.get_dummies(test_df['BsmtCond'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.137191Z","iopub.execute_input":"2022-07-08T11:46:32.137699Z","iopub.status.idle":"2022-07-08T11:46:32.154210Z","shell.execute_reply.started":"2022-07-08T11:46:32.137649Z","shell.execute_reply":"2022-07-08T11:46:32.152776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_heat = pd.get_dummies(test_df['HeatingQC'],drop_first=True)\ntest_cent_air = pd.get_dummies(test_df['CentralAir'],drop_first=True)\ntest_elect  = pd.get_dummies(test_df['Electrical'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.155796Z","iopub.execute_input":"2022-07-08T11:46:32.156697Z","iopub.status.idle":"2022-07-08T11:46:32.176377Z","shell.execute_reply.started":"2022-07-08T11:46:32.156648Z","shell.execute_reply":"2022-07-08T11:46:32.174533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_kit = pd.get_dummies(test_df['KitchenQual'],drop_first=True)\ntest_func = pd.get_dummies(test_df['Functional'],drop_first=True)\ntest_fire = pd.get_dummies(test_df['FireplaceQu'],drop_first=True)\ntest_garage_type = pd.get_dummies(test_df['GarageType'],drop_first=True)\ntest_garage_cond = pd.get_dummies(test_df['GarageCond'],drop_first=True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.179422Z","iopub.execute_input":"2022-07-08T11:46:32.179956Z","iopub.status.idle":"2022-07-08T11:46:32.194135Z","shell.execute_reply.started":"2022-07-08T11:46:32.179911Z","shell.execute_reply":"2022-07-08T11:46:32.192746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_pave = pd.get_dummies(test_df['PavedDrive'],drop_first=True)\ntest_fence = pd.get_dummies(test_df['Fence'],drop_first=True)\ntest_saletype = pd.get_dummies(test_df['SaleType'],drop_first=True)\ntest_salecon = pd.get_dummies(test_df['SaleCondition'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.195671Z","iopub.execute_input":"2022-07-08T11:46:32.197760Z","iopub.status.idle":"2022-07-08T11:46:32.207511Z","shell.execute_reply.started":"2022-07-08T11:46:32.197717Z","shell.execute_reply":"2022-07-08T11:46:32.206674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df1 = pd.concat([test_df,test_mszone,test_lot_shape,test_land_contour,test_lot_config,test_neighbor,\n                     test_cond,test_bldg,test_housestyle,test_roofstyle,test_ext2,test_mason,\n                      test_ext_cond,test_found,test_base,test_heat,test_cent_air,test_elect,\n                      test_kit,test_func,test_fire,test_garage_type,test_garage_cond,\n                     test_pave,test_fence,test_saletype,test_salecon],axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.208789Z","iopub.execute_input":"2022-07-08T11:46:32.209341Z","iopub.status.idle":"2022-07-08T11:46:32.225040Z","shell.execute_reply.started":"2022-07-08T11:46:32.209298Z","shell.execute_reply":"2022-07-08T11:46:32.223872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df1.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.226360Z","iopub.execute_input":"2022-07-08T11:46:32.227299Z","iopub.status.idle":"2022-07-08T11:46:32.253649Z","shell.execute_reply.started":"2022-07-08T11:46:32.227252Z","shell.execute_reply":"2022-07-08T11:46:32.252433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.255389Z","iopub.execute_input":"2022-07-08T11:46:32.255755Z","iopub.status.idle":"2022-07-08T11:46:32.275683Z","shell.execute_reply.started":"2022-07-08T11:46:32.255723Z","shell.execute_reply":"2022-07-08T11:46:32.274060Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df1.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.278668Z","iopub.execute_input":"2022-07-08T11:46:32.279551Z","iopub.status.idle":"2022-07-08T11:46:32.301417Z","shell.execute_reply.started":"2022-07-08T11:46:32.279498Z","shell.execute_reply":"2022-07-08T11:46:32.300270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df1.drop(['MSZoning','LotShape','LandContour','LotConfig','Neighborhood',\n              'Condition1','BldgType','HouseStyle','RoofStyle', 'Exterior2nd', 'MasVnrType',\n              'ExterCond', 'Foundation', 'BsmtCond','Heating','HeatingQC','CentralAir','Electrical',\n              'KitchenQual','Functional','FireplaceQu', 'GarageType', 'GarageFinish','GarageCond','PavedDrive',\n               'Fence','SaleType','SaleCondition'], axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.302993Z","iopub.execute_input":"2022-07-08T11:46:32.303331Z","iopub.status.idle":"2022-07-08T11:46:32.313196Z","shell.execute_reply.started":"2022-07-08T11:46:32.303301Z","shell.execute_reply":"2022-07-08T11:46:32.312026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df1.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.314983Z","iopub.execute_input":"2022-07-08T11:46:32.315357Z","iopub.status.idle":"2022-07-08T11:46:32.344218Z","shell.execute_reply.started":"2022-07-08T11:46:32.315324Z","shell.execute_reply":"2022-07-08T11:46:32.343101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df1.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.345142Z","iopub.execute_input":"2022-07-08T11:46:32.345470Z","iopub.status.idle":"2022-07-08T11:46:32.365233Z","shell.execute_reply.started":"2022-07-08T11:46:32.345440Z","shell.execute_reply":"2022-07-08T11:46:32.364295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(20,10))\nsns.heatmap(test_df1.isnull(),yticklabels = False,cbar =False, cmap='viridis')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:32.366551Z","iopub.execute_input":"2022-07-08T11:46:32.367158Z","iopub.status.idle":"2022-07-08T11:46:33.737489Z","shell.execute_reply.started":"2022-07-08T11:46:32.367126Z","shell.execute_reply":"2022-07-08T11:46:33.736167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df1['BsmtFinSF2']=test_df1['BsmtFinSF2'].fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:33.739485Z","iopub.execute_input":"2022-07-08T11:46:33.739929Z","iopub.status.idle":"2022-07-08T11:46:33.748417Z","shell.execute_reply.started":"2022-07-08T11:46:33.739887Z","shell.execute_reply":"2022-07-08T11:46:33.747184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df1['GarageCars']=test_df1['GarageCars'].fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:33.750008Z","iopub.execute_input":"2022-07-08T11:46:33.750338Z","iopub.status.idle":"2022-07-08T11:46:33.761551Z","shell.execute_reply.started":"2022-07-08T11:46:33.750307Z","shell.execute_reply":"2022-07-08T11:46:33.760709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df1['BsmtFinSF1']=test_df1['BsmtFinSF1'].fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:33.762679Z","iopub.execute_input":"2022-07-08T11:46:33.763405Z","iopub.status.idle":"2022-07-08T11:46:33.776125Z","shell.execute_reply.started":"2022-07-08T11:46:33.763373Z","shell.execute_reply":"2022-07-08T11:46:33.775176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df1 = test_df1.fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:33.777196Z","iopub.execute_input":"2022-07-08T11:46:33.777994Z","iopub.status.idle":"2022-07-08T11:46:33.788140Z","shell.execute_reply.started":"2022-07-08T11:46:33.777959Z","shell.execute_reply":"2022-07-08T11:46:33.786834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df1.isnull().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:33.790836Z","iopub.execute_input":"2022-07-08T11:46:33.791185Z","iopub.status.idle":"2022-07-08T11:46:33.805097Z","shell.execute_reply.started":"2022-07-08T11:46:33.791155Z","shell.execute_reply":"2022-07-08T11:46:33.804125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_lm_predictions = lm.predict(test_df1)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:33.806372Z","iopub.execute_input":"2022-07-08T11:46:33.807079Z","iopub.status.idle":"2022-07-08T11:46:33.822590Z","shell.execute_reply.started":"2022-07-08T11:46:33.807043Z","shell.execute_reply":"2022-07-08T11:46:33.821359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(test_lm_predictions)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:33.824251Z","iopub.execute_input":"2022-07-08T11:46:33.825076Z","iopub.status.idle":"2022-07-08T11:46:33.834235Z","shell.execute_reply.started":"2022-07-08T11:46:33.825026Z","shell.execute_reply":"2022-07-08T11:46:33.831642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df1.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:33.836897Z","iopub.execute_input":"2022-07-08T11:46:33.840126Z","iopub.status.idle":"2022-07-08T11:46:33.848900Z","shell.execute_reply.started":"2022-07-08T11:46:33.840068Z","shell.execute_reply":"2022-07-08T11:46:33.847690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_rfr_predictions = rfr.predict(test_df1)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:33.850856Z","iopub.execute_input":"2022-07-08T11:46:33.851821Z","iopub.status.idle":"2022-07-08T11:46:33.960021Z","shell.execute_reply.started":"2022-07-08T11:46:33.851765Z","shell.execute_reply":"2022-07-08T11:46:33.958890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SalePrice_LM = pd.Series(test_lm_predictions,name = 'SalePrice_LM')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:33.961373Z","iopub.execute_input":"2022-07-08T11:46:33.962337Z","iopub.status.idle":"2022-07-08T11:46:33.966963Z","shell.execute_reply.started":"2022-07-08T11:46:33.962301Z","shell.execute_reply":"2022-07-08T11:46:33.965960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SalePrice = pd.Series(test_rfr_predictions,name = 'SalePrice')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:33.968002Z","iopub.execute_input":"2022-07-08T11:46:33.969027Z","iopub.status.idle":"2022-07-08T11:46:33.981908Z","shell.execute_reply.started":"2022-07-08T11:46:33.968993Z","shell.execute_reply":"2022-07-08T11:46:33.980562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SalePrice_LM","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:46:34.002912Z","iopub.execute_input":"2022-07-08T11:46:34.003487Z","iopub.status.idle":"2022-07-08T11:46:34.016079Z","shell.execute_reply.started":"2022-07-08T11:46:34.003449Z","shell.execute_reply":"2022-07-08T11:46:34.014938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SalePrice","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:47:48.452249Z","iopub.execute_input":"2022-07-08T11:47:48.452697Z","iopub.status.idle":"2022-07-08T11:47:48.462945Z","shell.execute_reply.started":"2022-07-08T11:47:48.452661Z","shell.execute_reply":"2022-07-08T11:47:48.461649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"house_pred = pd.concat([test_df['Id'],SalePrice_LM,SalePrice],axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:48:00.174603Z","iopub.execute_input":"2022-07-08T11:48:00.174981Z","iopub.status.idle":"2022-07-08T11:48:00.182290Z","shell.execute_reply.started":"2022-07-08T11:48:00.174951Z","shell.execute_reply":"2022-07-08T11:48:00.180824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"house_pred.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:48:04.148191Z","iopub.execute_input":"2022-07-08T11:48:04.149245Z","iopub.status.idle":"2022-07-08T11:48:04.158720Z","shell.execute_reply.started":"2022-07-08T11:48:04.149188Z","shell.execute_reply":"2022-07-08T11:48:04.157318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,8))\nsns.heatmap(house_pred.isnull(),yticklabels = False,cbar=False,cmap='viridis')","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:48:07.386972Z","iopub.execute_input":"2022-07-08T11:48:07.387350Z","iopub.status.idle":"2022-07-08T11:48:07.546236Z","shell.execute_reply.started":"2022-07-08T11:48:07.387319Z","shell.execute_reply":"2022-07-08T11:48:07.545038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"house_pred.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:48:12.769857Z","iopub.execute_input":"2022-07-08T11:48:12.770280Z","iopub.status.idle":"2022-07-08T11:48:12.784340Z","shell.execute_reply.started":"2022-07-08T11:48:12.770247Z","shell.execute_reply":"2022-07-08T11:48:12.782334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_result = house_pred.drop('SalePrice_LM',axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:48:18.306279Z","iopub.execute_input":"2022-07-08T11:48:18.306849Z","iopub.status.idle":"2022-07-08T11:48:18.314388Z","shell.execute_reply.started":"2022-07-08T11:48:18.306809Z","shell.execute_reply":"2022-07-08T11:48:18.312771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_result","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:48:22.261031Z","iopub.execute_input":"2022-07-08T11:48:22.261459Z","iopub.status.idle":"2022-07-08T11:48:22.277238Z","shell.execute_reply.started":"2022-07-08T11:48:22.261425Z","shell.execute_reply":"2022-07-08T11:48:22.275879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# we will convert our final result into csv file\nfinal_result.to_csv('house_prices.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T11:48:28.492825Z","iopub.execute_input":"2022-07-08T11:48:28.493207Z","iopub.status.idle":"2022-07-08T11:48:28.507403Z","shell.execute_reply.started":"2022-07-08T11:48:28.493177Z","shell.execute_reply":"2022-07-08T11:48:28.506503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}