{"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-14T05:59:52.157030Z","iopub.execute_input":"2022-07-14T05:59:52.157530Z","iopub.status.idle":"2022-07-14T05:59:52.164722Z","shell.execute_reply.started":"2022-07-14T05:59:52.157481Z","shell.execute_reply":"2022-07-14T05:59:52.163696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport warnings \nwarnings.filterwarnings('ignore')\nimport seaborn as sns\n","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:52.170642Z","iopub.execute_input":"2022-07-14T05:59:52.171418Z","iopub.status.idle":"2022-07-14T05:59:53.361077Z","shell.execute_reply.started":"2022-07-14T05:59:52.171363Z","shell.execute_reply":"2022-07-14T05:59:53.360118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(r'/kaggle/input/house-prices-advanced-regression-techniques/train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:53.362527Z","iopub.execute_input":"2022-07-14T05:59:53.363233Z","iopub.status.idle":"2022-07-14T05:59:53.405788Z","shell.execute_reply.started":"2022-07-14T05:59:53.363199Z","shell.execute_reply":"2022-07-14T05:59:53.404803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2022-07-14T05:59:53.407417Z","iopub.execute_input":"2022-07-14T05:59:53.408093Z","iopub.status.idle":"2022-07-14T05:59:53.443211Z","shell.execute_reply.started":"2022-07-14T05:59:53.408044Z","shell.execute_reply":"2022-07-14T05:59:53.442464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:53.444823Z","iopub.execute_input":"2022-07-14T05:59:53.445262Z","iopub.status.idle":"2022-07-14T05:59:53.450822Z","shell.execute_reply.started":"2022-07-14T05:59:53.445232Z","shell.execute_reply":"2022-07-14T05:59:53.449954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv(r'/kaggle/input/house-prices-advanced-regression-techniques/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:53.451996Z","iopub.execute_input":"2022-07-14T05:59:53.452442Z","iopub.status.idle":"2022-07-14T05:59:53.490268Z","shell.execute_reply.started":"2022-07-14T05:59:53.452387Z","shell.execute_reply":"2022-07-14T05:59:53.489364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:53.491673Z","iopub.execute_input":"2022-07-14T05:59:53.492129Z","iopub.status.idle":"2022-07-14T05:59:53.513960Z","shell.execute_reply.started":"2022-07-14T05:59:53.492096Z","shell.execute_reply":"2022-07-14T05:59:53.513021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Merging the data both train and test to maintain consistency.","metadata":{}},{"cell_type":"code","source":"data = pd.concat([train,test])","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:12:09.626986Z","iopub.execute_input":"2022-07-14T06:12:09.627649Z","iopub.status.idle":"2022-07-14T06:12:09.648968Z","shell.execute_reply.started":"2022-07-14T06:12:09.627599Z","shell.execute_reply":"2022-07-14T06:12:09.647796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Let us get some info","metadata":{}},{"cell_type":"code","source":"data.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:53.546484Z","iopub.execute_input":"2022-07-14T05:59:53.546981Z","iopub.status.idle":"2022-07-14T05:59:53.553775Z","shell.execute_reply.started":"2022-07-14T05:59:53.546934Z","shell.execute_reply":"2022-07-14T05:59:53.552990Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:53.555055Z","iopub.execute_input":"2022-07-14T05:59:53.555483Z","iopub.status.idle":"2022-07-14T05:59:53.599533Z","shell.execute_reply.started":"2022-07-14T05:59:53.555451Z","shell.execute_reply":"2022-07-14T05:59:53.598363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.describe(include='all').T","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:53.603102Z","iopub.execute_input":"2022-07-14T05:59:53.604025Z","iopub.status.idle":"2022-07-14T05:59:53.765949Z","shell.execute_reply.started":"2022-07-14T05:59:53.603974Z","shell.execute_reply":"2022-07-14T05:59:53.764745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### lets find  the duplicates","metadata":{}},{"cell_type":"code","source":"data.duplicated().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:53.767892Z","iopub.execute_input":"2022-07-14T05:59:53.768429Z","iopub.status.idle":"2022-07-14T05:59:53.800316Z","shell.execute_reply.started":"2022-07-14T05:59:53.768361Z","shell.execute_reply":"2022-07-14T05:59:53.799604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Lets clean the data and try to drop the unwanted columns","metadata":{}},{"cell_type":"markdown","source":"### Find the missing Values","metadata":{}},{"cell_type":"code","source":"pd.set_option('display.max_rows', None)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:53.801599Z","iopub.execute_input":"2022-07-14T05:59:53.802078Z","iopub.status.idle":"2022-07-14T05:59:53.806384Z","shell.execute_reply.started":"2022-07-14T05:59:53.802046Z","shell.execute_reply":"2022-07-14T05:59:53.805479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:53.807612Z","iopub.execute_input":"2022-07-14T05:59:53.808207Z","iopub.status.idle":"2022-07-14T05:59:53.832880Z","shell.execute_reply.started":"2022-07-14T05:59:53.808132Z","shell.execute_reply":"2022-07-14T05:59:53.831861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.figure(figsize=(15,12))\nsns.heatmap(data.isnull(),yticklabels=False,cbar=False,cmap='YlGnBu')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:53.834276Z","iopub.execute_input":"2022-07-14T05:59:53.835349Z","iopub.status.idle":"2022-07-14T05:59:55.357046Z","shell.execute_reply.started":"2022-07-14T05:59:53.835304Z","shell.execute_reply":"2022-07-14T05:59:55.356114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### dropping the columns which have more than 50 percent null values","metadata":{}},{"cell_type":"code","source":"data.isnull().sum().sort_values(ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.358787Z","iopub.execute_input":"2022-07-14T05:59:55.359255Z","iopub.status.idle":"2022-07-14T05:59:55.381614Z","shell.execute_reply.started":"2022-07-14T05:59:55.359209Z","shell.execute_reply":"2022-07-14T05:59:55.380307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.shape   # Combined data of both train and test ","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.383198Z","iopub.execute_input":"2022-07-14T05:59:55.383659Z","iopub.status.idle":"2022-07-14T05:59:55.390061Z","shell.execute_reply.started":"2022-07-14T05:59:55.383615Z","shell.execute_reply":"2022-07-14T05:59:55.389328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### We could see four features (PoolQC,MiscFeature,Alley,Fence) have more than 50 percent nulldata, so we are dropping these columns. And also dropping Id column which is not required for modelling.\n    ","metadata":{}},{"cell_type":"code","source":"data.drop(columns=['PoolQC','Fence','MiscFeature','Alley','Id'], axis =1 , inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.391390Z","iopub.execute_input":"2022-07-14T05:59:55.391964Z","iopub.status.idle":"2022-07-14T05:59:55.407256Z","shell.execute_reply.started":"2022-07-14T05:59:55.391931Z","shell.execute_reply":"2022-07-14T05:59:55.406076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(columns=['SalePrice'], axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.410261Z","iopub.execute_input":"2022-07-14T05:59:55.411306Z","iopub.status.idle":"2022-07-14T05:59:55.417902Z","shell.execute_reply.started":"2022-07-14T05:59:55.411268Z","shell.execute_reply":"2022-07-14T05:59:55.416955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.shape    ## five columns dropped","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.418827Z","iopub.execute_input":"2022-07-14T05:59:55.419466Z","iopub.status.idle":"2022-07-14T05:59:55.428830Z","shell.execute_reply.started":"2022-07-14T05:59:55.419425Z","shell.execute_reply":"2022-07-14T05:59:55.427777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Handling missing values","metadata":{}},{"cell_type":"code","source":"object_columns = [i for i in data.columns if data[i].dtype == 'object']\nlen(object_columns)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.430540Z","iopub.execute_input":"2022-07-14T05:59:55.430965Z","iopub.status.idle":"2022-07-14T05:59:55.444776Z","shell.execute_reply.started":"2022-07-14T05:59:55.430917Z","shell.execute_reply":"2022-07-14T05:59:55.443791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"object_columns","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.446589Z","iopub.execute_input":"2022-07-14T05:59:55.447287Z","iopub.status.idle":"2022-07-14T05:59:55.454951Z","shell.execute_reply.started":"2022-07-14T05:59:55.447245Z","shell.execute_reply":"2022-07-14T05:59:55.453900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numerical_columns = [i for i in data.columns if data[i].dtype in ['int64', 'float64']]\nlen(numerical_columns)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.456221Z","iopub.execute_input":"2022-07-14T05:59:55.456635Z","iopub.status.idle":"2022-07-14T05:59:55.470814Z","shell.execute_reply.started":"2022-07-14T05:59:55.456596Z","shell.execute_reply":"2022-07-14T05:59:55.469587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numerical_columns","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.472142Z","iopub.execute_input":"2022-07-14T05:59:55.473391Z","iopub.status.idle":"2022-07-14T05:59:55.481650Z","shell.execute_reply.started":"2022-07-14T05:59:55.473345Z","shell.execute_reply":"2022-07-14T05:59:55.480896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## 39 + 36  = 75  - we have segregated the categorical and numerical columns to handle missing values respectively","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.482704Z","iopub.execute_input":"2022-07-14T05:59:55.483320Z","iopub.status.idle":"2022-07-14T05:59:55.491327Z","shell.execute_reply.started":"2022-07-14T05:59:55.483287Z","shell.execute_reply":"2022-07-14T05:59:55.490584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def HandleMissingValues(df):\n    values = {}\n    for i in object_columns:\n        values[i] = df[i].mode()[0]\n    for i in numerical_columns:\n        values[i] = df[i].mean()\n    df.fillna(value=values,inplace=True)\nHandleMissingValues(data)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.492354Z","iopub.execute_input":"2022-07-14T05:59:55.493038Z","iopub.status.idle":"2022-07-14T05:59:55.540465Z","shell.execute_reply.started":"2022-07-14T05:59:55.493006Z","shell.execute_reply":"2022-07-14T05:59:55.539382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isnull().sum()        # null values has been handled","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.541718Z","iopub.execute_input":"2022-07-14T05:59:55.542143Z","iopub.status.idle":"2022-07-14T05:59:55.558682Z","shell.execute_reply.started":"2022-07-14T05:59:55.542102Z","shell.execute_reply":"2022-07-14T05:59:55.557686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### One hot encoding the categorical values","metadata":{}},{"cell_type":"code","source":"def dummy_df(df, dummy_col_list):\n    for x in dummy_col_list:\n        dummies = pd.get_dummies(df[x], dummy_na=False)\n        df =df.drop(x,1)\n        df =pd.concat([df,dummies], axis =1)\n    return df\n","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.559991Z","iopub.execute_input":"2022-07-14T05:59:55.561578Z","iopub.status.idle":"2022-07-14T05:59:55.568637Z","shell.execute_reply.started":"2022-07-14T05:59:55.561525Z","shell.execute_reply":"2022-07-14T05:59:55.567819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = dummy_df(data,object_columns)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.573342Z","iopub.execute_input":"2022-07-14T05:59:55.574528Z","iopub.status.idle":"2022-07-14T05:59:55.906261Z","shell.execute_reply.started":"2022-07-14T05:59:55.574473Z","shell.execute_reply":"2022-07-14T05:59:55.905522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.907370Z","iopub.execute_input":"2022-07-14T05:59:55.907725Z","iopub.status.idle":"2022-07-14T05:59:55.914831Z","shell.execute_reply.started":"2022-07-14T05:59:55.907692Z","shell.execute_reply":"2022-07-14T05:59:55.913668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Removing the duplicated columns ","metadata":{}},{"cell_type":"code","source":"final_data =data.loc[:,~data.columns.duplicated()]","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.916550Z","iopub.execute_input":"2022-07-14T05:59:55.917267Z","iopub.status.idle":"2022-07-14T05:59:55.927095Z","shell.execute_reply.started":"2022-07-14T05:59:55.917223Z","shell.execute_reply":"2022-07-14T05:59:55.926122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_data.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.928071Z","iopub.execute_input":"2022-07-14T05:59:55.928829Z","iopub.status.idle":"2022-07-14T05:59:55.940485Z","shell.execute_reply.started":"2022-07-14T05:59:55.928796Z","shell.execute_reply":"2022-07-14T05:59:55.938875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#spliting the data into train and test separately\ntrain_data=final_data.iloc[:1460,:]\ntest_data=final_data.iloc[1460:,:]\nprint(train_data.shape)\ntest_data.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.942109Z","iopub.execute_input":"2022-07-14T05:59:55.942485Z","iopub.status.idle":"2022-07-14T05:59:55.949068Z","shell.execute_reply.started":"2022-07-14T05:59:55.942444Z","shell.execute_reply":"2022-07-14T05:59:55.948328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Modelling data","metadata":{}},{"cell_type":"code","source":"from sklearn.linear_model import LinearRegression\nfrom sklearn.metrics import mean_squared_error,r2_score","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:55.950063Z","iopub.execute_input":"2022-07-14T05:59:55.950780Z","iopub.status.idle":"2022-07-14T05:59:56.290538Z","shell.execute_reply.started":"2022-07-14T05:59:55.950748Z","shell.execute_reply":"2022-07-14T05:59:56.289621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=train_data\ny=train.loc[:,'SalePrice']","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.291921Z","iopub.execute_input":"2022-07-14T05:59:56.292815Z","iopub.status.idle":"2022-07-14T05:59:56.299335Z","shell.execute_reply.started":"2022-07-14T05:59:56.292740Z","shell.execute_reply":"2022-07-14T05:59:56.298565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.300554Z","iopub.execute_input":"2022-07-14T05:59:56.301620Z","iopub.status.idle":"2022-07-14T05:59:56.338336Z","shell.execute_reply.started":"2022-07-14T05:59:56.301583Z","shell.execute_reply":"2022-07-14T05:59:56.337105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.340143Z","iopub.execute_input":"2022-07-14T05:59:56.340680Z","iopub.status.idle":"2022-07-14T05:59:56.351801Z","shell.execute_reply.started":"2022-07-14T05:59:56.340645Z","shell.execute_reply":"2022-07-14T05:59:56.350367Z"},"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-14T05:59:56.353510Z","iopub.execute_input":"2022-07-14T05:59:56.354224Z","iopub.status.idle":"2022-07-14T05:59:56.361923Z","shell.execute_reply.started":"2022-07-14T05:59:56.354157Z","shell.execute_reply":"2022-07-14T05:59:56.361130Z"},"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.2,random_state=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.364165Z","iopub.execute_input":"2022-07-14T05:59:56.364873Z","iopub.status.idle":"2022-07-14T05:59:56.379256Z","shell.execute_reply.started":"2022-07-14T05:59:56.364761Z","shell.execute_reply":"2022-07-14T05:59:56.377492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model =LinearRegression()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.380511Z","iopub.execute_input":"2022-07-14T05:59:56.380829Z","iopub.status.idle":"2022-07-14T05:59:56.386386Z","shell.execute_reply.started":"2022-07-14T05:59:56.380800Z","shell.execute_reply":"2022-07-14T05:59:56.385453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.388697Z","iopub.execute_input":"2022-07-14T05:59:56.389949Z","iopub.status.idle":"2022-07-14T05:59:56.472443Z","shell.execute_reply.started":"2022-07-14T05:59:56.389901Z","shell.execute_reply":"2022-07-14T05:59:56.471477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.coef_","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.473689Z","iopub.execute_input":"2022-07-14T05:59:56.474563Z","iopub.status.idle":"2022-07-14T05:59:56.493455Z","shell.execute_reply.started":"2022-07-14T05:59:56.474519Z","shell.execute_reply":"2022-07-14T05:59:56.492431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.intercept_","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.495394Z","iopub.execute_input":"2022-07-14T05:59:56.497332Z","iopub.status.idle":"2022-07-14T05:59:56.505378Z","shell.execute_reply.started":"2022-07-14T05:59:56.497280Z","shell.execute_reply":"2022-07-14T05:59:56.504101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train_pred = model.predict(x_train)\nx_test_pred = model.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.506944Z","iopub.execute_input":"2022-07-14T05:59:56.509289Z","iopub.status.idle":"2022-07-14T05:59:56.565555Z","shell.execute_reply.started":"2022-07-14T05:59:56.509219Z","shell.execute_reply":"2022-07-14T05:59:56.564094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#actual data from hackathon\ntest_pred = model.predict(test_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.569594Z","iopub.execute_input":"2022-07-14T05:59:56.571093Z","iopub.status.idle":"2022-07-14T05:59:56.585765Z","shell.execute_reply.started":"2022-07-14T05:59:56.571030Z","shell.execute_reply":"2022-07-14T05:59:56.584497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train_rmse = np.sqrt(mean_squared_error(y_train,x_train_pred))\nx_test_rmse = np.sqrt(mean_squared_error(y_test,x_test_pred))","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.587824Z","iopub.execute_input":"2022-07-14T05:59:56.588748Z","iopub.status.idle":"2022-07-14T05:59:56.597048Z","shell.execute_reply.started":"2022-07-14T05:59:56.588694Z","shell.execute_reply":"2022-07-14T05:59:56.595868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('x_train_rmse is',x_train_rmse )\nprint('x_test_rmse is',x_test_rmse )","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.599189Z","iopub.execute_input":"2022-07-14T05:59:56.600202Z","iopub.status.idle":"2022-07-14T05:59:56.606970Z","shell.execute_reply.started":"2022-07-14T05:59:56.600145Z","shell.execute_reply":"2022-07-14T05:59:56.605803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train_r2 = r2_score(y_train,x_train_pred)\nx_test_r2 =r2_score(y_test,x_test_pred)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.609772Z","iopub.execute_input":"2022-07-14T05:59:56.610652Z","iopub.status.idle":"2022-07-14T05:59:56.620013Z","shell.execute_reply.started":"2022-07-14T05:59:56.610601Z","shell.execute_reply":"2022-07-14T05:59:56.618699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('x_train_r2 is',x_train_r2 )\nprint('x_test_r2 is',x_test_r2 )","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.621968Z","iopub.execute_input":"2022-07-14T05:59:56.622945Z","iopub.status.idle":"2022-07-14T05:59:56.632510Z","shell.execute_reply.started":"2022-07-14T05:59:56.622889Z","shell.execute_reply":"2022-07-14T05:59:56.631220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_pred_modified= np.where(test_pred<0, 0, test_pred)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.634054Z","iopub.execute_input":"2022-07-14T05:59:56.635224Z","iopub.status.idle":"2022-07-14T05:59:56.651660Z","shell.execute_reply.started":"2022-07-14T05:59:56.635172Z","shell.execute_reply":"2022-07-14T05:59:56.650367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['SalePrice'] = test_pred_modified","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.654034Z","iopub.execute_input":"2022-07-14T05:59:56.654784Z","iopub.status.idle":"2022-07-14T05:59:56.664880Z","shell.execute_reply.started":"2022-07-14T05:59:56.654737Z","shell.execute_reply":"2022-07-14T05:59:56.663287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Output = test[['Id','SalePrice']]","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.666674Z","iopub.execute_input":"2022-07-14T05:59:56.667503Z","iopub.status.idle":"2022-07-14T05:59:56.677203Z","shell.execute_reply.started":"2022-07-14T05:59:56.667448Z","shell.execute_reply":"2022-07-14T05:59:56.676101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Output.to_csv('House_prediction_linear_Regression_80_percent_data.csv', index = False)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:59:56.678798Z","iopub.execute_input":"2022-07-14T05:59:56.679451Z","iopub.status.idle":"2022-07-14T05:59:56.707054Z","shell.execute_reply.started":"2022-07-14T05:59:56.679379Z","shell.execute_reply":"2022-07-14T05:59:56.705941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def model_predict(model,x_train,y_train,test,filename):\n    train_pred = model.predict(x_train)\n    test_pred = model.predict(test_data) \n    train_rmse = np.sqrt(mean_squared_error(y_train,train_pred))\n    print('train_rmse is',train_rmse )\n    train_r2 = r2_score(y_train,train_pred)\n    print('train_r2 is', train_r2 )\n    test_pred_modified= np.where(test_pred<0, 0, test_pred)\n    test['SalePrice'] = test_pred_modified\n    Output = test[['Id','SalePrice']]\n    Output.to_csv(filename, index = False)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:14:20.042348Z","iopub.execute_input":"2022-07-14T06:14:20.042842Z","iopub.status.idle":"2022-07-14T06:14:20.050877Z","shell.execute_reply.started":"2022-07-14T06:14:20.042804Z","shell.execute_reply":"2022-07-14T06:14:20.049802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model =LinearRegression()\nmodel.fit(x,y)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:14:20.530614Z","iopub.execute_input":"2022-07-14T06:14:20.531083Z","iopub.status.idle":"2022-07-14T06:14:20.629800Z","shell.execute_reply.started":"2022-07-14T06:14:20.531046Z","shell.execute_reply":"2022-07-14T06:14:20.623440Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_predict(model, x, y,test ,'Houseprediction_Linearregression.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:14:20.961274Z","iopub.execute_input":"2022-07-14T06:14:20.961768Z","iopub.status.idle":"2022-07-14T06:14:20.998640Z","shell.execute_reply.started":"2022-07-14T06:14:20.961731Z","shell.execute_reply":"2022-07-14T06:14:20.997472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.neighbors import KNeighborsRegressor\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.tree import DecisionTreeRegressor","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:18:05.205947Z","iopub.execute_input":"2022-07-14T06:18:05.206381Z","iopub.status.idle":"2022-07-14T06:18:05.211941Z","shell.execute_reply.started":"2022-07-14T06:18:05.206347Z","shell.execute_reply":"2022-07-14T06:18:05.210804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = KNeighborsRegressor()\nmodel.fit(x,y)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:18:38.811046Z","iopub.execute_input":"2022-07-14T06:18:38.811497Z","iopub.status.idle":"2022-07-14T06:18:38.825328Z","shell.execute_reply.started":"2022-07-14T06:18:38.811460Z","shell.execute_reply":"2022-07-14T06:18:38.824306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_predict(model, x, y,test ,'Houseprediction_kneighbors.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:18:39.341163Z","iopub.execute_input":"2022-07-14T06:18:39.342246Z","iopub.status.idle":"2022-07-14T06:18:39.567557Z","shell.execute_reply.started":"2022-07-14T06:18:39.342191Z","shell.execute_reply":"2022-07-14T06:18:39.566396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = RandomForestRegressor(max_depth=6)\nmodel.fit(x,y)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:19:46.507104Z","iopub.execute_input":"2022-07-14T06:19:46.507603Z","iopub.status.idle":"2022-07-14T06:19:47.749214Z","shell.execute_reply.started":"2022-07-14T06:19:46.507554Z","shell.execute_reply":"2022-07-14T06:19:47.747758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_predict(model, x, y,test ,'Houseprediction_randomforest.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:19:47.750843Z","iopub.execute_input":"2022-07-14T06:19:47.751186Z","iopub.status.idle":"2022-07-14T06:19:47.810111Z","shell.execute_reply.started":"2022-07-14T06:19:47.751155Z","shell.execute_reply":"2022-07-14T06:19:47.809393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = DecisionTreeRegressor(max_depth=6)\nmodel.fit(x,y)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:20:20.126229Z","iopub.execute_input":"2022-07-14T06:20:20.126647Z","iopub.status.idle":"2022-07-14T06:20:20.157851Z","shell.execute_reply.started":"2022-07-14T06:20:20.126616Z","shell.execute_reply":"2022-07-14T06:20:20.156827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_predict(model, x, y,test ,'Houseprediction_Decisiontree.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:20:20.501572Z","iopub.execute_input":"2022-07-14T06:20:20.502597Z","iopub.status.idle":"2022-07-14T06:20:20.528933Z","shell.execute_reply.started":"2022-07-14T06:20:20.502544Z","shell.execute_reply":"2022-07-14T06:20:20.527554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}