{"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":"markdown","source":"## Loading Libraries","metadata":{"id":"89YEnP98M725"}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nfrom pandas.plotting import scatter_matrix\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.metrics import mean_absolute_error\nfrom sklearn.model_selection import GridSearchCV\n\nimport warnings\n\nwarnings.filterwarnings('ignore')\n%matplotlib inline\n\npd.set_option('display.max_columns',None)\nsns.set_theme('notebook')","metadata":{"id":"s77l6SlMIIeu","execution":{"iopub.status.busy":"2022-08-04T14:18:01.719354Z","iopub.execute_input":"2022-08-04T14:18:01.720559Z","iopub.status.idle":"2022-08-04T14:18:03.005988Z","shell.execute_reply.started":"2022-08-04T14:18:01.720181Z","shell.execute_reply":"2022-08-04T14:18:03.004797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Loading Train Data","metadata":{"id":"ovr7KOSHMZ1n"}},{"cell_type":"code","source":"housing_train=pd.read_csv(\"../input/house-prices-advanced-regression-techniques/train.csv\")","metadata":{"id":"rFcG01ITLbUD","execution":{"iopub.status.busy":"2022-08-04T14:18:03.007815Z","iopub.execute_input":"2022-08-04T14:18:03.008190Z","iopub.status.idle":"2022-08-04T14:18:03.060085Z","shell.execute_reply.started":"2022-08-04T14:18:03.008158Z","shell.execute_reply":"2022-08-04T14:18:03.059384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## checking data's shape","metadata":{"id":"TbebED_tMm1y"}},{"cell_type":"code","source":"housing_train.shape\n","metadata":{"id":"doc5r1geMENS","outputId":"b08ed3ab-46e1-4225-ecc5-5d0e0d5c45d7","execution":{"iopub.status.busy":"2022-08-04T14:18:03.061577Z","iopub.execute_input":"2022-08-04T14:18:03.062100Z","iopub.status.idle":"2022-08-04T14:18:03.072090Z","shell.execute_reply.started":"2022-08-04T14:18:03.062056Z","shell.execute_reply":"2022-08-04T14:18:03.071127Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Checking missing values on train data","metadata":{"id":"wIUdfBVDNHzJ"}},{"cell_type":"code","source":"housing_train.info()","metadata":{"id":"PzMEOtT7MRmw","outputId":"ef90783f-953a-486d-cfb1-c306839c8249","execution":{"iopub.status.busy":"2022-08-04T14:18:03.073058Z","iopub.execute_input":"2022-08-04T14:18:03.074032Z","iopub.status.idle":"2022-08-04T14:18:03.109389Z","shell.execute_reply.started":"2022-08-04T14:18:03.073912Z","shell.execute_reply":"2022-08-04T14:18:03.108567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Checking random 10 observations \n","metadata":{"id":"R11Dwn8MIBwk"}},{"cell_type":"code","source":"housing_train.sample(10)","metadata":{"id":"zePlXaLtNvaB","outputId":"9168516e-43c8-47c6-82d0-61b5a2f07822","execution":{"iopub.status.busy":"2022-08-04T14:18:03.111291Z","iopub.execute_input":"2022-08-04T14:18:03.111676Z","iopub.status.idle":"2022-08-04T14:18:03.184976Z","shell.execute_reply.started":"2022-08-04T14:18:03.111647Z","shell.execute_reply":"2022-08-04T14:18:03.184131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Test Statistics and Correlations","metadata":{"id":"0oNsPYYXImXB"}},{"cell_type":"code","source":"housing_train.describe().T","metadata":{"id":"WiB9Ubupyy7k","outputId":"8e16c081-8735-4885-f14f-93dce17cf04d","execution":{"iopub.status.busy":"2022-08-04T14:18:03.186340Z","iopub.execute_input":"2022-08-04T14:18:03.187042Z","iopub.status.idle":"2022-08-04T14:18:03.296047Z","shell.execute_reply.started":"2022-08-04T14:18:03.187007Z","shell.execute_reply":"2022-08-04T14:18:03.295150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"housing_train.corr().T","metadata":{"id":"m_71IqiGpe4g","outputId":"c000158a-0872-4694-dc2c-baf6f254f664","execution":{"iopub.status.busy":"2022-08-04T14:18:03.297688Z","iopub.execute_input":"2022-08-04T14:18:03.298241Z","iopub.status.idle":"2022-08-04T14:18:03.380413Z","shell.execute_reply.started":"2022-08-04T14:18:03.298192Z","shell.execute_reply":"2022-08-04T14:18:03.379493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Spilting Data","metadata":{"id":"tYNI5qqCTD9G"}},{"cell_type":"code","source":"X=housing_train.copy()\ny=X.pop('SalePrice')","metadata":{"id":"LyoGjCE08z_f","execution":{"iopub.status.busy":"2022-08-04T14:18:03.381668Z","iopub.execute_input":"2022-08-04T14:18:03.382352Z","iopub.status.idle":"2022-08-04T14:18:03.388678Z","shell.execute_reply.started":"2022-08-04T14:18:03.382322Z","shell.execute_reply":"2022-08-04T14:18:03.387480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train,X_valid, y_train, y_valid = train_test_split(X, y, test_size=0.25, random_state=42)","metadata":{"id":"O5PRiWn1-v-s","execution":{"iopub.status.busy":"2022-08-04T14:18:03.390288Z","iopub.execute_input":"2022-08-04T14:18:03.390518Z","iopub.status.idle":"2022-08-04T14:18:03.407972Z","shell.execute_reply.started":"2022-08-04T14:18:03.390492Z","shell.execute_reply":"2022-08-04T14:18:03.406926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Function to convert Float values of columns into int","metadata":{"id":"me6wan0eopLu"}},{"cell_type":"code","source":"def float_int(df):\n  float_list=df.select_dtypes('float64').columns.tolist()\n  for f_col in float_list:\n    df[f_col].fillna(0,inplace=True)\n    df[f_col]=pd.to_numeric(df[f_col],errors='coerce').astype(int)\n  return df","metadata":{"id":"iXPD0_N6Ng-v","execution":{"iopub.status.busy":"2022-08-04T14:18:03.409598Z","iopub.execute_input":"2022-08-04T14:18:03.409843Z","iopub.status.idle":"2022-08-04T14:18:03.415846Z","shell.execute_reply.started":"2022-08-04T14:18:03.409816Z","shell.execute_reply":"2022-08-04T14:18:03.414994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_copy=float_int(X_train)\nX_train=X_train_copy.copy()","metadata":{"id":"QnpeXEt1PGxg","execution":{"iopub.status.busy":"2022-08-04T14:18:03.416995Z","iopub.execute_input":"2022-08-04T14:18:03.417548Z","iopub.status.idle":"2022-08-04T14:18:03.433650Z","shell.execute_reply.started":"2022-08-04T14:18:03.417516Z","shell.execute_reply":"2022-08-04T14:18:03.432704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid_copy=float_int(X_valid)\nX_valid=X_valid_copy.copy()","metadata":{"id":"kTVouzoq3ZY0","execution":{"iopub.status.busy":"2022-08-04T14:18:03.435133Z","iopub.execute_input":"2022-08-04T14:18:03.435481Z","iopub.status.idle":"2022-08-04T14:18:03.447339Z","shell.execute_reply.started":"2022-08-04T14:18:03.435447Z","shell.execute_reply":"2022-08-04T14:18:03.446499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Function count how many missing values in the dataset\n","metadata":{"id":"DQnesoXub7qC"}},{"cell_type":"code","source":"def count_less(data):\n  shape_data=data.shape[0]\n  count_dict={}\n  for col_name in data.columns:\n    if(data[col_name].isna().sum()<=shape_data):\n      count_dict[col_name]=data[col_name].isna().sum()\n  count_dict={key:value for key,value in count_dict.items() if (value)!=0}\n  count_dict=dict(sorted(count_dict.items(),key=lambda x:x[1],reverse=True))\n  count_dict_df=pd.DataFrame(count_dict.items(),columns=['Column Names','Missing Values'])\n  return count_dict_df","metadata":{"id":"oTZ93V6RLdnL","execution":{"iopub.status.busy":"2022-08-04T14:18:03.448546Z","iopub.execute_input":"2022-08-04T14:18:03.448904Z","iopub.status.idle":"2022-08-04T14:18:03.461469Z","shell.execute_reply.started":"2022-08-04T14:18:03.448876Z","shell.execute_reply":"2022-08-04T14:18:03.460516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_list=count_less(X_train)\n","metadata":{"id":"uaW5b1qZLjvD","execution":{"iopub.status.busy":"2022-08-04T14:18:03.464908Z","iopub.execute_input":"2022-08-04T14:18:03.465192Z","iopub.status.idle":"2022-08-04T14:18:03.511006Z","shell.execute_reply.started":"2022-08-04T14:18:03.465162Z","shell.execute_reply":"2022-08-04T14:18:03.510017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid_list=count_less(X_valid)\n","metadata":{"id":"n7ua97UhULLq","execution":{"iopub.status.busy":"2022-08-04T14:18:03.512447Z","iopub.execute_input":"2022-08-04T14:18:03.512702Z","iopub.status.idle":"2022-08-04T14:18:03.557250Z","shell.execute_reply.started":"2022-08-04T14:18:03.512672Z","shell.execute_reply":"2022-08-04T14:18:03.556201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Removing the columns who has more than half of missing values","metadata":{"id":"Ofg6KTfuMOXn"}},{"cell_type":"code","source":"X_train.drop(columns=X_train_list['Column Names'][:5],axis=1,inplace=True)","metadata":{"id":"iLx3OGZtLjow","execution":{"iopub.status.busy":"2022-08-04T14:18:03.558737Z","iopub.execute_input":"2022-08-04T14:18:03.559091Z","iopub.status.idle":"2022-08-04T14:18:03.570717Z","shell.execute_reply.started":"2022-08-04T14:18:03.559046Z","shell.execute_reply":"2022-08-04T14:18:03.569856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid.drop(columns=X_valid_list['Column Names'][:5],axis=1,inplace=True)","metadata":{"id":"5EVYMw2aUkuy","execution":{"iopub.status.busy":"2022-08-04T14:18:03.572076Z","iopub.execute_input":"2022-08-04T14:18:03.572346Z","iopub.status.idle":"2022-08-04T14:18:03.583642Z","shell.execute_reply.started":"2022-08-04T14:18:03.572318Z","shell.execute_reply":"2022-08-04T14:18:03.582640Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"id":"teYT5dj7lclo","outputId":"bc124c28-7c9f-4ceb-94cd-b75da6f16c2c","execution":{"iopub.status.busy":"2022-08-04T14:18:03.584642Z","iopub.execute_input":"2022-08-04T14:18:03.585069Z","iopub.status.idle":"2022-08-04T14:18:03.599173Z","shell.execute_reply.started":"2022-08-04T14:18:03.585039Z","shell.execute_reply":"2022-08-04T14:18:03.598269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid.shape","metadata":{"id":"RprR81Fsle_N","outputId":"09a36e42-9e89-4b9e-d027-a183d68569ba","execution":{"iopub.status.busy":"2022-08-04T14:18:03.600363Z","iopub.execute_input":"2022-08-04T14:18:03.600627Z","iopub.status.idle":"2022-08-04T14:18:03.610487Z","shell.execute_reply.started":"2022-08-04T14:18:03.600596Z","shell.execute_reply":"2022-08-04T14:18:03.609647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Feature Engineering ","metadata":{"id":"pnI5t_Y9Hh0X"}},{"cell_type":"code","source":"X_train['Age']=(X_train['YrSold'] - X_train['YearBuilt']) ","metadata":{"id":"PF3GuwAaHhYA","execution":{"iopub.status.busy":"2022-08-04T14:18:03.612056Z","iopub.execute_input":"2022-08-04T14:18:03.612784Z","iopub.status.idle":"2022-08-04T14:18:03.621072Z","shell.execute_reply.started":"2022-08-04T14:18:03.612738Z","shell.execute_reply":"2022-08-04T14:18:03.620374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid['Age']=(X_valid['YrSold'] - X_valid['YearBuilt']) ","metadata":{"id":"nC6XY_O1V4dH","execution":{"iopub.status.busy":"2022-08-04T14:18:03.622593Z","iopub.execute_input":"2022-08-04T14:18:03.623155Z","iopub.status.idle":"2022-08-04T14:18:03.634319Z","shell.execute_reply.started":"2022-08-04T14:18:03.623088Z","shell.execute_reply":"2022-08-04T14:18:03.633322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Removing irrelevant Features","metadata":{"id":"rQGrK665pGYA"}},{"cell_type":"code","source":"drop_list=['Id','LotFrontage','OverallCond','BsmtFinSF2','BsmtFinSF1','BsmtUnfSF','2ndFlrSF','LowQualFinSF','BsmtFullBath','BsmtHalfBath','HalfBath','BedroomAbvGr','KitchenAbvGr','Fireplaces','GarageYrBlt','GarageArea','OpenPorchSF','EnclosedPorch','3SsnPorch','ScreenPorch','PoolArea','MiscVal','MoSold','YrSold','YearBuilt','Condition2']","metadata":{"id":"28KOpmRSA7ZE","execution":{"iopub.status.busy":"2022-08-04T14:18:03.635947Z","iopub.execute_input":"2022-08-04T14:18:03.637098Z","iopub.status.idle":"2022-08-04T14:18:03.645678Z","shell.execute_reply.started":"2022-08-04T14:18:03.636995Z","shell.execute_reply":"2022-08-04T14:18:03.645001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.drop(drop_list,axis=1,inplace=True)","metadata":{"id":"JrHrIpqGA7VI","execution":{"iopub.status.busy":"2022-08-04T14:18:03.646873Z","iopub.execute_input":"2022-08-04T14:18:03.647721Z","iopub.status.idle":"2022-08-04T14:18:03.660008Z","shell.execute_reply.started":"2022-08-04T14:18:03.647675Z","shell.execute_reply":"2022-08-04T14:18:03.659271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid.drop(drop_list,axis=1,inplace=True)","metadata":{"id":"UxREdxYAWCaV","execution":{"iopub.status.busy":"2022-08-04T14:18:03.661736Z","iopub.execute_input":"2022-08-04T14:18:03.662359Z","iopub.status.idle":"2022-08-04T14:18:03.669057Z","shell.execute_reply.started":"2022-08-04T14:18:03.662314Z","shell.execute_reply":"2022-08-04T14:18:03.668439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.head(5)","metadata":{"id":"afxTu9NXYg1L","outputId":"e10662ee-1185-46c5-ad51-e75ea9397af7","execution":{"iopub.status.busy":"2022-08-04T14:18:03.670811Z","iopub.execute_input":"2022-08-04T14:18:03.671390Z","iopub.status.idle":"2022-08-04T14:18:03.718262Z","shell.execute_reply.started":"2022-08-04T14:18:03.671348Z","shell.execute_reply":"2022-08-04T14:18:03.717124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"id":"9SFBiA3cbO0p","outputId":"b6709f21-c51a-4ea3-ef24-e8e0f67bc2d4","execution":{"iopub.status.busy":"2022-08-04T14:18:03.721717Z","iopub.execute_input":"2022-08-04T14:18:03.721994Z","iopub.status.idle":"2022-08-04T14:18:03.729482Z","shell.execute_reply.started":"2022-08-04T14:18:03.721962Z","shell.execute_reply":"2022-08-04T14:18:03.728613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid.head(5)","metadata":{"id":"t57eEIuvYqzx","outputId":"41f3e7d9-db63-4fb0-c840-40bcb7137750","execution":{"iopub.status.busy":"2022-08-04T14:18:03.730941Z","iopub.execute_input":"2022-08-04T14:18:03.731216Z","iopub.status.idle":"2022-08-04T14:18:03.782568Z","shell.execute_reply.started":"2022-08-04T14:18:03.731186Z","shell.execute_reply":"2022-08-04T14:18:03.781707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid.shape","metadata":{"id":"Asbo5eFcbQ4j","outputId":"3164cb65-6eaa-42b9-bf78-8ec7a1425fb9","execution":{"iopub.status.busy":"2022-08-04T14:18:03.783995Z","iopub.execute_input":"2022-08-04T14:18:03.784655Z","iopub.status.idle":"2022-08-04T14:18:03.794520Z","shell.execute_reply.started":"2022-08-04T14:18:03.784612Z","shell.execute_reply":"2022-08-04T14:18:03.793634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Removing object columns who have more than 50 % of values count to single variable","metadata":{"id":"TNCSn72Wry1L"}},{"cell_type":"code","source":"remove_list=['MSZoning','Street','LotShape','LandContour','Utilities','LotConfig','LandSlope','Neighborhood','Condition1','BldgType',\n 'HouseStyle','RoofStyle','RoofMatl','Exterior1st','Exterior2nd','MasVnrType','ExterQual','ExterCond','Foundation','BsmtQual','BsmtCond',\n 'BsmtExposure','BsmtFinType1','BsmtFinType2','Heating','HeatingQC','CentralAir','Electrical','KitchenQual','Functional','GarageType',\n 'GarageFinish','GarageQual','GarageCond','PavedDrive','SaleType','SaleCondition']","metadata":{"id":"a0GdToXABON-","execution":{"iopub.status.busy":"2022-08-04T14:18:03.795877Z","iopub.execute_input":"2022-08-04T14:18:03.796534Z","iopub.status.idle":"2022-08-04T14:18:03.805119Z","shell.execute_reply.started":"2022-08-04T14:18:03.796491Z","shell.execute_reply":"2022-08-04T14:18:03.804475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.drop(remove_list,1,inplace=True)","metadata":{"id":"HSfsnq6nGHOv","execution":{"iopub.status.busy":"2022-08-04T14:18:03.806476Z","iopub.execute_input":"2022-08-04T14:18:03.807297Z","iopub.status.idle":"2022-08-04T14:18:03.816051Z","shell.execute_reply.started":"2022-08-04T14:18:03.807259Z","shell.execute_reply":"2022-08-04T14:18:03.815253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid.drop(remove_list,1,inplace=True)","metadata":{"id":"_-9P6OMqWVov","execution":{"iopub.status.busy":"2022-08-04T14:18:03.817564Z","iopub.execute_input":"2022-08-04T14:18:03.818344Z","iopub.status.idle":"2022-08-04T14:18:03.827579Z","shell.execute_reply.started":"2022-08-04T14:18:03.818310Z","shell.execute_reply":"2022-08-04T14:18:03.826861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train","metadata":{"id":"ss-1NmTouOgm","outputId":"ed5210a9-40c3-4605-8a14-3f7bbfa62689","execution":{"iopub.status.busy":"2022-08-04T14:18:03.829362Z","iopub.execute_input":"2022-08-04T14:18:03.829599Z","iopub.status.idle":"2022-08-04T14:18:03.851312Z","shell.execute_reply.started":"2022-08-04T14:18:03.829563Z","shell.execute_reply":"2022-08-04T14:18:03.850396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Removing the outliers ","metadata":{"id":"1PZEqXKT3Sdf"}},{"cell_type":"code","source":"def remove_out(df):\n  for col_name in df.columns:\n    q1 = np.quantile(df[col_name],0.25)\n    q3=np.quantile(df[col_name],0.75)\n    iqr=q3 - q1\n    lb=q1 - 1.5 * iqr\n    up= q3 + 1.5 * iqr\n    df_copy=df[~((df[col_name]<lb) | (df[col_name]>up))]\n  return df_copy\n\n\n","metadata":{"id":"8DL-Uq8_WcP7","execution":{"iopub.status.busy":"2022-08-04T14:18:03.852503Z","iopub.execute_input":"2022-08-04T14:18:03.852764Z","iopub.status.idle":"2022-08-04T14:18:03.858763Z","shell.execute_reply.started":"2022-08-04T14:18:03.852729Z","shell.execute_reply":"2022-08-04T14:18:03.858189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train=remove_out(X_train)","metadata":{"id":"K5evVCRtXneI","execution":{"iopub.status.busy":"2022-08-04T14:18:03.859881Z","iopub.execute_input":"2022-08-04T14:18:03.860243Z","iopub.status.idle":"2022-08-04T14:18:03.886807Z","shell.execute_reply.started":"2022-08-04T14:18:03.860214Z","shell.execute_reply":"2022-08-04T14:18:03.885857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid=remove_out(X_valid)","metadata":{"id":"XgsMxyhOXvG5","execution":{"iopub.status.busy":"2022-08-04T14:18:03.887985Z","iopub.execute_input":"2022-08-04T14:18:03.888271Z","iopub.status.idle":"2022-08-04T14:18:03.909523Z","shell.execute_reply.started":"2022-08-04T14:18:03.888236Z","shell.execute_reply":"2022-08-04T14:18:03.908527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## EDA & Data Visualization","metadata":{"id":"sveTx4quvvVp"}},{"cell_type":"code","source":"sns.pairplot(X_train)\nplt.xticks(rotation=90)\nplt.yticks(rotation=90)\nplt.show()","metadata":{"id":"HDUU3Sp_x9SZ","outputId":"6d64df18-c428-4d54-fa78-59b44ad410ca","execution":{"iopub.status.busy":"2022-08-04T14:18:03.910960Z","iopub.execute_input":"2022-08-04T14:18:03.911248Z","iopub.status.idle":"2022-08-04T14:18:38.672218Z","shell.execute_reply.started":"2022-08-04T14:18:03.911217Z","shell.execute_reply":"2022-08-04T14:18:38.671213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='OverallQual',y='TotRmsAbvGrd',data=X_train)\nplt.show()","metadata":{"id":"TfPLTb5SkEh6","outputId":"f9ad3cb3-52e0-4925-b28a-dbaa60a6cfa7","execution":{"iopub.status.busy":"2022-08-04T14:18:38.674304Z","iopub.execute_input":"2022-08-04T14:18:38.674567Z","iopub.status.idle":"2022-08-04T14:18:39.343990Z","shell.execute_reply.started":"2022-08-04T14:18:38.674538Z","shell.execute_reply":"2022-08-04T14:18:39.343354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='OverallQual',y='YearRemodAdd',data=X_train)\nplt.show()","metadata":{"id":"YEwLjfEmt6Ve","outputId":"d90e9cb5-8e5d-4495-f4aa-ef77ab93822d","execution":{"iopub.status.busy":"2022-08-04T14:18:39.344919Z","iopub.execute_input":"2022-08-04T14:18:39.345479Z","iopub.status.idle":"2022-08-04T14:18:40.017968Z","shell.execute_reply.started":"2022-08-04T14:18:39.345445Z","shell.execute_reply":"2022-08-04T14:18:40.016909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='YearRemodAdd',y='Age',data=X_train)\nplt.show()","metadata":{"id":"C8hlqZ69wd0c","outputId":"64f6115d-812b-4f5a-823e-14986f7e4cb1","execution":{"iopub.status.busy":"2022-08-04T14:18:40.019555Z","iopub.execute_input":"2022-08-04T14:18:40.020000Z","iopub.status.idle":"2022-08-04T14:18:40.702913Z","shell.execute_reply.started":"2022-08-04T14:18:40.019960Z","shell.execute_reply":"2022-08-04T14:18:40.702243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='MasVnrArea',y='YearRemodAdd',data=X_train)\nplt.show()","metadata":{"id":"5zLMDC4swdyH","outputId":"0b04a165-13f7-4d42-8771-d654851cb8a6","execution":{"iopub.status.busy":"2022-08-04T14:18:40.704203Z","iopub.execute_input":"2022-08-04T14:18:40.704623Z","iopub.status.idle":"2022-08-04T14:18:41.406208Z","shell.execute_reply.started":"2022-08-04T14:18:40.704576Z","shell.execute_reply":"2022-08-04T14:18:41.405499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='MasVnrArea',y='TotRmsAbvGrd',data=X_train)\nplt.show()\n","metadata":{"id":"dZpJ3byBwdvT","outputId":"cd0f2291-1b96-49bc-8e79-0602f5371041","execution":{"iopub.status.busy":"2022-08-04T14:18:41.411541Z","iopub.execute_input":"2022-08-04T14:18:41.412479Z","iopub.status.idle":"2022-08-04T14:18:42.091568Z","shell.execute_reply.started":"2022-08-04T14:18:41.412430Z","shell.execute_reply":"2022-08-04T14:18:42.090678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='OverallQual',y='TotalBsmtSF',data=X_train)\nplt.show()\n","metadata":{"id":"3C8aE64u0Ot6","outputId":"2ccdcf46-27b8-4edc-ea60-5adfb06ed648","execution":{"iopub.status.busy":"2022-08-04T14:18:42.092917Z","iopub.execute_input":"2022-08-04T14:18:42.093462Z","iopub.status.idle":"2022-08-04T14:18:42.745745Z","shell.execute_reply.started":"2022-08-04T14:18:42.093420Z","shell.execute_reply":"2022-08-04T14:18:42.744819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_co=X_train.copy()\nX_train_co['TotalBsmtSF']=np.log(X_train_co['TotalBsmtSF'])\nX_train_co['YearRemodAdd']=np.log(X_train_co['YearRemodAdd'])\n\nsns.regplot(x='TotalBsmtSF',y='YearRemodAdd',data=X_train_co)\nplt.show()\n","metadata":{"id":"rxOPfCv5fGJt","outputId":"066964dc-ba2e-4f32-b677-66b7c37ee91d","execution":{"iopub.status.busy":"2022-08-04T14:18:42.747475Z","iopub.execute_input":"2022-08-04T14:18:42.747810Z","iopub.status.idle":"2022-08-04T14:18:43.360630Z","shell.execute_reply.started":"2022-08-04T14:18:42.747770Z","shell.execute_reply":"2022-08-04T14:18:43.359633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_co=X_train.copy()\nX_train_co['TotalBsmtSF']=np.log(X_train['TotalBsmtSF'])\nX_train_co['1stFlrSF']=np.log(X_train['1stFlrSF'])\nsns.lmplot(x='TotalBsmtSF',y='1stFlrSF',data=X_train_co)\nplt.show()\n","metadata":{"id":"LV2nA2YPfGHJ","outputId":"2a1dac88-69b4-44c7-f955-fad215c2f8d4","execution":{"iopub.status.busy":"2022-08-04T14:18:43.361783Z","iopub.execute_input":"2022-08-04T14:18:43.362022Z","iopub.status.idle":"2022-08-04T14:18:44.170549Z","shell.execute_reply.started":"2022-08-04T14:18:43.361994Z","shell.execute_reply":"2022-08-04T14:18:44.169625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='TotalBsmtSF',y='GrLivArea',data=X_train)\nplt.show()\n","metadata":{"id":"kBq6rJsmfGEg","outputId":"6c998d45-6652-495a-96e8-4f8be144d29e","execution":{"iopub.status.busy":"2022-08-04T14:18:44.171751Z","iopub.execute_input":"2022-08-04T14:18:44.172031Z","iopub.status.idle":"2022-08-04T14:18:44.840891Z","shell.execute_reply.started":"2022-08-04T14:18:44.171999Z","shell.execute_reply":"2022-08-04T14:18:44.839922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='TotalBsmtSF',y='TotRmsAbvGrd',data=X_train)\nplt.show()\n#useless","metadata":{"id":"j9OrhGr6wCOe","outputId":"480a3f14-570a-45a6-82e8-5869cd596ddf","execution":{"iopub.status.busy":"2022-08-04T14:18:44.842667Z","iopub.execute_input":"2022-08-04T14:18:44.843009Z","iopub.status.idle":"2022-08-04T14:18:45.526422Z","shell.execute_reply.started":"2022-08-04T14:18:44.842964Z","shell.execute_reply":"2022-08-04T14:18:45.525348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='TotalBsmtSF',y='WoodDeckSF',data=X_train)\nplt.show()\n#useless","metadata":{"id":"zN7oMpgjAh5C","outputId":"0bc97ec9-9f09-44bf-db4c-85b3d225a3e7","execution":{"iopub.status.busy":"2022-08-04T14:18:45.528156Z","iopub.execute_input":"2022-08-04T14:18:45.528467Z","iopub.status.idle":"2022-08-04T14:18:46.243299Z","shell.execute_reply.started":"2022-08-04T14:18:45.528428Z","shell.execute_reply":"2022-08-04T14:18:46.242468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='TotalBsmtSF',y='Age',data=X_train)\nplt.show()","metadata":{"id":"c_evJI00Ah2e","outputId":"0d947684-1c9d-45d4-e37e-c3bb9748f433","execution":{"iopub.status.busy":"2022-08-04T14:18:46.244653Z","iopub.execute_input":"2022-08-04T14:18:46.244924Z","iopub.status.idle":"2022-08-04T14:18:46.948574Z","shell.execute_reply.started":"2022-08-04T14:18:46.244895Z","shell.execute_reply":"2022-08-04T14:18:46.947626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='1stFlrSF',y='YearRemodAdd',data=X_train)\nplt.show()","metadata":{"id":"dBDeus3ZwCLB","outputId":"639d9afa-dd37-4f9e-cba2-8becd9dd540f","execution":{"iopub.status.busy":"2022-08-04T14:18:46.950185Z","iopub.execute_input":"2022-08-04T14:18:46.950826Z","iopub.status.idle":"2022-08-04T14:18:47.634375Z","shell.execute_reply.started":"2022-08-04T14:18:46.950792Z","shell.execute_reply":"2022-08-04T14:18:47.633255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='1stFlrSF',y='MasVnrArea',data=X_train)\nplt.show()","metadata":{"id":"LmAbysxRCYFn","outputId":"126a0d67-b80d-43af-9b9e-000c864f4976","execution":{"iopub.status.busy":"2022-08-04T14:18:47.635737Z","iopub.execute_input":"2022-08-04T14:18:47.636238Z","iopub.status.idle":"2022-08-04T14:18:48.309951Z","shell.execute_reply.started":"2022-08-04T14:18:47.636203Z","shell.execute_reply":"2022-08-04T14:18:48.308727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='1stFlrSF',y='GrLivArea',data=X_train)\nplt.show()","metadata":{"id":"CewJ4ZLjCYCz","outputId":"a495599f-fda1-4e5f-e979-32d2293bf978","execution":{"iopub.status.busy":"2022-08-04T14:18:48.311615Z","iopub.execute_input":"2022-08-04T14:18:48.311934Z","iopub.status.idle":"2022-08-04T14:18:48.968651Z","shell.execute_reply.started":"2022-08-04T14:18:48.311904Z","shell.execute_reply":"2022-08-04T14:18:48.967700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='1stFlrSF',y='Age',data=X_train)\nplt.show()","metadata":{"id":"MCNgJn2mCYAI","outputId":"f3d4733e-e63c-4e81-acff-b69135dc6fbd","execution":{"iopub.status.busy":"2022-08-04T14:18:48.970051Z","iopub.execute_input":"2022-08-04T14:18:48.970334Z","iopub.status.idle":"2022-08-04T14:18:49.627600Z","shell.execute_reply.started":"2022-08-04T14:18:48.970305Z","shell.execute_reply":"2022-08-04T14:18:49.626887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='GrLivArea',y='OverallQual',data=X_train)\nplt.show()","metadata":{"id":"O4mcoeZUNrAT","outputId":"97607793-0769-45c8-f7e6-fa8b80acbc02","execution":{"iopub.status.busy":"2022-08-04T14:18:49.629059Z","iopub.execute_input":"2022-08-04T14:18:49.630000Z","iopub.status.idle":"2022-08-04T14:18:50.287569Z","shell.execute_reply.started":"2022-08-04T14:18:49.629959Z","shell.execute_reply":"2022-08-04T14:18:50.286709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='GrLivArea',y='Age',data=X_train)\nplt.show()","metadata":{"id":"BZTJcxedNq9t","outputId":"20742563-ca87-4960-d147-ccbeb1dc2b98","execution":{"iopub.status.busy":"2022-08-04T14:18:50.289315Z","iopub.execute_input":"2022-08-04T14:18:50.289896Z","iopub.status.idle":"2022-08-04T14:18:50.946253Z","shell.execute_reply.started":"2022-08-04T14:18:50.289856Z","shell.execute_reply":"2022-08-04T14:18:50.945151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='TotRmsAbvGrd',y='YearRemodAdd',data=X_train)\nplt.show()","metadata":{"id":"7XOVvV-QNq62","outputId":"d3549212-ffbb-4738-bf46-f38c5dbbe128","execution":{"iopub.status.busy":"2022-08-04T14:18:50.947817Z","iopub.execute_input":"2022-08-04T14:18:50.948181Z","iopub.status.idle":"2022-08-04T14:18:51.633474Z","shell.execute_reply.started":"2022-08-04T14:18:50.948140Z","shell.execute_reply":"2022-08-04T14:18:51.632578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='TotRmsAbvGrd',y='GrLivArea',data=X_train)\nplt.show()","metadata":{"id":"ytx0HRTBUasL","outputId":"ad440feb-deb2-4488-bb3a-ffe8713d2dab","execution":{"iopub.status.busy":"2022-08-04T14:18:51.634591Z","iopub.execute_input":"2022-08-04T14:18:51.635201Z","iopub.status.idle":"2022-08-04T14:18:52.300831Z","shell.execute_reply.started":"2022-08-04T14:18:51.635169Z","shell.execute_reply":"2022-08-04T14:18:52.299998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='TotRmsAbvGrd',y='WoodDeckSF',data=X_train)\nplt.show()","metadata":{"id":"tz6q797yUapZ","outputId":"b792e629-8922-4ef8-dadd-4a0d85793aff","execution":{"iopub.status.busy":"2022-08-04T14:18:52.302008Z","iopub.execute_input":"2022-08-04T14:18:52.302274Z","iopub.status.idle":"2022-08-04T14:18:53.515865Z","shell.execute_reply.started":"2022-08-04T14:18:52.302245Z","shell.execute_reply":"2022-08-04T14:18:53.515242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='TotRmsAbvGrd',y='Age',data=X_train)\nplt.show()","metadata":{"id":"Js08xF1tUanA","outputId":"3f26f39a-3582-482f-dc2a-31b05c42198e","execution":{"iopub.status.busy":"2022-08-04T14:18:53.517163Z","iopub.execute_input":"2022-08-04T14:18:53.518041Z","iopub.status.idle":"2022-08-04T14:18:54.160143Z","shell.execute_reply.started":"2022-08-04T14:18:53.517990Z","shell.execute_reply":"2022-08-04T14:18:54.159264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.lmplot(x='WoodDeckSF',y='Age',data=X_train)\nplt.show()","metadata":{"id":"f53E9qdabaY5","outputId":"0d8dd6b7-484a-4cac-a40c-1ad83bcec328","execution":{"iopub.status.busy":"2022-08-04T14:18:54.161510Z","iopub.execute_input":"2022-08-04T14:18:54.162462Z","iopub.status.idle":"2022-08-04T14:18:54.780839Z","shell.execute_reply.started":"2022-08-04T14:18:54.162416Z","shell.execute_reply":"2022-08-04T14:18:54.779951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Concat training and valid  data","metadata":{"id":"8z8Cz38owaG5"}},{"cell_type":"code","source":"housing_price_copy_train=pd.concat([X_train,y_train],1)","metadata":{"id":"pdVeZA2X-hWP","execution":{"iopub.status.busy":"2022-08-04T14:18:54.782253Z","iopub.execute_input":"2022-08-04T14:18:54.782574Z","iopub.status.idle":"2022-08-04T14:18:54.791932Z","shell.execute_reply.started":"2022-08-04T14:18:54.782536Z","shell.execute_reply":"2022-08-04T14:18:54.791045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"housing_price_copy_valid=pd.concat([X_valid,y_valid],1)","metadata":{"id":"KfrdRvmaB-Ah","execution":{"iopub.status.busy":"2022-08-04T14:18:54.793445Z","iopub.execute_input":"2022-08-04T14:18:54.793774Z","iopub.status.idle":"2022-08-04T14:18:54.803316Z","shell.execute_reply.started":"2022-08-04T14:18:54.793727Z","shell.execute_reply":"2022-08-04T14:18:54.802453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"drop_list_col=['MasVnrArea','WoodDeckSF']","metadata":{"id":"9LYQv0X3-ubR","execution":{"iopub.status.busy":"2022-08-04T14:18:54.804607Z","iopub.execute_input":"2022-08-04T14:18:54.805070Z","iopub.status.idle":"2022-08-04T14:18:54.815174Z","shell.execute_reply.started":"2022-08-04T14:18:54.805018Z","shell.execute_reply":"2022-08-04T14:18:54.814275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"housing_price_copy_train.drop(drop_list_col,1,inplace=True)","metadata":{"id":"a7ryg8xb-1id","execution":{"iopub.status.busy":"2022-08-04T14:18:54.816710Z","iopub.execute_input":"2022-08-04T14:18:54.817527Z","iopub.status.idle":"2022-08-04T14:18:54.827862Z","shell.execute_reply.started":"2022-08-04T14:18:54.817492Z","shell.execute_reply":"2022-08-04T14:18:54.826961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"housing_price_copy_valid.drop(drop_list_col,1,inplace=True)","metadata":{"id":"F7lOj4bW72lS","execution":{"iopub.status.busy":"2022-08-04T14:18:54.829665Z","iopub.execute_input":"2022-08-04T14:18:54.830027Z","iopub.status.idle":"2022-08-04T14:18:54.839187Z","shell.execute_reply.started":"2022-08-04T14:18:54.829989Z","shell.execute_reply":"2022-08-04T14:18:54.838383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Respliting Data","metadata":{"id":"7XbK3dDewyvL"}},{"cell_type":"code","source":"X_train=housing_price_copy_train.copy()\ny_train=X_train.pop('SalePrice')","metadata":{"id":"mON865ICCQwO","execution":{"iopub.status.busy":"2022-08-04T14:18:54.840680Z","iopub.execute_input":"2022-08-04T14:18:54.841212Z","iopub.status.idle":"2022-08-04T14:18:54.852149Z","shell.execute_reply.started":"2022-08-04T14:18:54.841170Z","shell.execute_reply":"2022-08-04T14:18:54.851241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid=housing_price_copy_valid.copy()\ny_valid=X_valid.pop('SalePrice')","metadata":{"id":"bvJcIcoI-wdX","execution":{"iopub.status.busy":"2022-08-04T14:18:54.853265Z","iopub.execute_input":"2022-08-04T14:18:54.853893Z","iopub.status.idle":"2022-08-04T14:18:54.866366Z","shell.execute_reply.started":"2022-08-04T14:18:54.853862Z","shell.execute_reply":"2022-08-04T14:18:54.865514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"id":"Kmwcztw_DPnT","outputId":"ee6eba20-cb9c-481a-a1f5-38e7ec4634c2","execution":{"iopub.status.busy":"2022-08-04T14:18:54.867677Z","iopub.execute_input":"2022-08-04T14:18:54.868411Z","iopub.status.idle":"2022-08-04T14:18:54.877417Z","shell.execute_reply.started":"2022-08-04T14:18:54.868368Z","shell.execute_reply":"2022-08-04T14:18:54.876494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train.shape","metadata":{"id":"zioUR_ksDPUz","outputId":"7cbc0666-d586-4a9e-95b4-004bf73a0b73","execution":{"iopub.status.busy":"2022-08-04T14:18:54.878847Z","iopub.execute_input":"2022-08-04T14:18:54.879194Z","iopub.status.idle":"2022-08-04T14:18:54.889156Z","shell.execute_reply.started":"2022-08-04T14:18:54.879155Z","shell.execute_reply":"2022-08-04T14:18:54.888228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid.shape","metadata":{"id":"c_Bd0ecyDOJr","outputId":"408ecff4-25a1-44ec-8eff-8221010f0155","execution":{"iopub.status.busy":"2022-08-04T14:18:54.890624Z","iopub.execute_input":"2022-08-04T14:18:54.891354Z","iopub.status.idle":"2022-08-04T14:18:54.899509Z","shell.execute_reply.started":"2022-08-04T14:18:54.891319Z","shell.execute_reply":"2022-08-04T14:18:54.898651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_valid.shape","metadata":{"id":"aP0rk3xLDN69","outputId":"2d441b17-2d3c-4b56-b02c-8b3c32ecfd61","execution":{"iopub.status.busy":"2022-08-04T14:18:54.901023Z","iopub.execute_input":"2022-08-04T14:18:54.901505Z","iopub.status.idle":"2022-08-04T14:18:54.912439Z","shell.execute_reply.started":"2022-08-04T14:18:54.901468Z","shell.execute_reply":"2022-08-04T14:18:54.911761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.head(10)","metadata":{"id":"2L81ERoU-mi3","outputId":"a14a9a22-2f4a-45d8-be1e-28766ddfb8f9","execution":{"iopub.status.busy":"2022-08-04T14:18:54.913618Z","iopub.execute_input":"2022-08-04T14:18:54.914314Z","iopub.status.idle":"2022-08-04T14:18:54.944724Z","shell.execute_reply.started":"2022-08-04T14:18:54.914275Z","shell.execute_reply":"2022-08-04T14:18:54.944155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train=float_int(X_train)","metadata":{"id":"c569DpF_Em8H","execution":{"iopub.status.busy":"2022-08-04T14:18:54.945627Z","iopub.execute_input":"2022-08-04T14:18:54.946502Z","iopub.status.idle":"2022-08-04T14:18:54.962836Z","shell.execute_reply.started":"2022-08-04T14:18:54.946458Z","shell.execute_reply":"2022-08-04T14:18:54.962122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid=float_int(X_valid)","metadata":{"id":"aHaCtZQ-HPgW","execution":{"iopub.status.busy":"2022-08-04T14:18:54.964537Z","iopub.execute_input":"2022-08-04T14:18:54.965059Z","iopub.status.idle":"2022-08-04T14:18:54.981233Z","shell.execute_reply.started":"2022-08-04T14:18:54.965017Z","shell.execute_reply":"2022-08-04T14:18:54.980597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Scaling the data","metadata":{"id":"219adS4X7OaG"}},{"cell_type":"code","source":"scaler=StandardScaler()","metadata":{"id":"UTsQLZvi_Ax0","execution":{"iopub.status.busy":"2022-08-04T14:18:54.982559Z","iopub.execute_input":"2022-08-04T14:18:54.983049Z","iopub.status.idle":"2022-08-04T14:18:54.987662Z","shell.execute_reply.started":"2022-08-04T14:18:54.983010Z","shell.execute_reply":"2022-08-04T14:18:54.986820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train=scaler.fit_transform(X_train)\nX_valid=scaler.transform(X_valid)","metadata":{"id":"coj_pePx_mb7","execution":{"iopub.status.busy":"2022-08-04T14:18:54.989130Z","iopub.execute_input":"2022-08-04T14:18:54.989603Z","iopub.status.idle":"2022-08-04T14:18:55.003453Z","shell.execute_reply.started":"2022-08-04T14:18:54.989565Z","shell.execute_reply":"2022-08-04T14:18:55.002431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Model : RandomForestRegressor","metadata":{"id":"Pe-l_nGv7XeQ"}},{"cell_type":"code","source":"model=RandomForestRegressor(random_state=1)","metadata":{"id":"XGKgq9SY_rfZ","execution":{"iopub.status.busy":"2022-08-04T14:18:55.004901Z","iopub.execute_input":"2022-08-04T14:18:55.005262Z","iopub.status.idle":"2022-08-04T14:18:55.009496Z","shell.execute_reply.started":"2022-08-04T14:18:55.005236Z","shell.execute_reply":"2022-08-04T14:18:55.008865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Parameter Tunning","metadata":{"id":"hU8dx03u7eUF"}},{"cell_type":"code","source":"param_grid={\n    'n_estimators':[150, 300, 390, 500, 600],\n    'min_samples_leaf': [2,3,4,5,7],\n    'min_samples_split': [2, 3, 5, 8, 10],\n    'max_features': [2, 3, 5, 7, 9]\n    }\n","metadata":{"id":"dZ4UVdN-A244","execution":{"iopub.status.busy":"2022-08-04T14:18:55.010439Z","iopub.execute_input":"2022-08-04T14:18:55.011180Z","iopub.status.idle":"2022-08-04T14:18:55.020661Z","shell.execute_reply.started":"2022-08-04T14:18:55.011151Z","shell.execute_reply":"2022-08-04T14:18:55.019729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Grid Search","metadata":{"id":"5UZKt8ep7keU"}},{"cell_type":"code","source":"grid_search=GridSearchCV(estimator=model,param_grid=param_grid,cv=5,n_jobs=-1,verbose=2,)","metadata":{"id":"J_BYuFxsAaml","execution":{"iopub.status.busy":"2022-08-04T14:18:55.021970Z","iopub.execute_input":"2022-08-04T14:18:55.022311Z","iopub.status.idle":"2022-08-04T14:18:55.031684Z","shell.execute_reply.started":"2022-08-04T14:18:55.022281Z","shell.execute_reply":"2022-08-04T14:18:55.030715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grid_search.fit(X_train,y_train)","metadata":{"id":"vrhWKdt1_0go","outputId":"9bfbee6f-ac17-42d0-a283-e72d7f26b24f","execution":{"iopub.status.busy":"2022-08-04T14:18:55.032977Z","iopub.execute_input":"2022-08-04T14:18:55.033257Z","iopub.status.idle":"2022-08-04T14:40:15.424529Z","shell.execute_reply.started":"2022-08-04T14:18:55.033228Z","shell.execute_reply":"2022-08-04T14:40:15.423303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Testing Model on test data","metadata":{"id":"FFOSrxmx7tEo"}},{"cell_type":"code","source":"def evaluate(model, test_features, test_labels):\n    predictions = model.predict(test_features)\n    mean_ab_err=mean_absolute_error(test_labels,predictions)\n    print('mean absolute error',mean_ab_err)\n    return mean_ab_err","metadata":{"id":"IjZuiez5SWur","execution":{"iopub.status.busy":"2022-08-04T14:40:15.426375Z","iopub.execute_input":"2022-08-04T14:40:15.426676Z","iopub.status.idle":"2022-08-04T14:40:15.434627Z","shell.execute_reply.started":"2022-08-04T14:40:15.426640Z","shell.execute_reply":"2022-08-04T14:40:15.433207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_grid=grid_search.best_estimator_","metadata":{"id":"HaC9dCxj7iMP","execution":{"iopub.status.busy":"2022-08-04T14:40:15.436260Z","iopub.execute_input":"2022-08-04T14:40:15.436553Z","iopub.status.idle":"2022-08-04T14:40:15.446487Z","shell.execute_reply.started":"2022-08-04T14:40:15.436520Z","shell.execute_reply":"2022-08-04T14:40:15.445461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grid_accuracy=evaluate(best_grid,X_valid,y_valid)","metadata":{"id":"55Urfs_nQG6v","outputId":"ae4ab2e9-6b7b-4aa1-a629-0b01f83a1b03","execution":{"iopub.status.busy":"2022-08-04T14:40:15.448220Z","iopub.execute_input":"2022-08-04T14:40:15.448892Z","iopub.status.idle":"2022-08-04T14:40:15.481306Z","shell.execute_reply.started":"2022-08-04T14:40:15.448846Z","shell.execute_reply":"2022-08-04T14:40:15.480275Z"},"trusted":true},"execution_count":null,"outputs":[]}]}