{"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":"\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom sklearn.impute import SimpleImputer\nfrom sklearn import preprocessing\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.preprocessing import LabelEncoder\nimport seaborn as sns\nimport warnings\nfrom sklearn.decomposition import PCA\n\nwarnings.filterwarnings('ignore')\n%matplotlib inline\nimport warnings\n\ndef fxn():\n    warnings.warn(\"deprecated\", DeprecationWarning)\n\nwith warnings.catch_warnings():\n    warnings.simplefilter(\"ignore\")\n    fxn()\n\n","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":1.940565,"end_time":"2022-07-21T19:16:35.892520","exception":false,"start_time":"2022-07-21T19:16:33.951955","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-07-31T22:33:27.255981Z","iopub.execute_input":"2022-07-31T22:33:27.256403Z","iopub.status.idle":"2022-07-31T22:33:27.268472Z","shell.execute_reply.started":"2022-07-31T22:33:27.256345Z","shell.execute_reply":"2022-07-31T22:33:27.267499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data = pd.read_csv(r'../input/house-prices-advanced-regression-techniques/train.csv')\nData.head(5)","metadata":{"papermill":{"duration":0.099546,"end_time":"2022-07-21T19:16:36.002751","exception":false,"start_time":"2022-07-21T19:16:35.903205","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-07-31T22:33:27.270718Z","iopub.execute_input":"2022-07-31T22:33:27.271348Z","iopub.status.idle":"2022-07-31T22:33:27.324287Z","shell.execute_reply.started":"2022-07-31T22:33:27.271309Z","shell.execute_reply":"2022-07-31T22:33:27.323343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.graph_objects as go\nimport plotly.express as px\nTaa=Data\ncols=Data.select_dtypes(exclude ='object').columns\ncols=cols.drop(['HalfBath','BsmtFullBath','BsmtHalfBath','BedroomAbvGr','KitchenAbvGr','TotRmsAbvGrd','EnclosedPorch'])\nfig = go.Figure(data=\n    go.Parcoords(line = dict(color = Taa['SalePrice'], colorscale =px.colors.sequential.Reds),\n        dimensions = [dict(label=col, values=Taa[col]) for col in cols]))\n\nfig.update_layout(\n    title=\"Dates\")\nfig.update_layout(\n    autosize=False,\n    width=2100,\n    height=800,)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:27.325516Z","iopub.execute_input":"2022-07-31T22:33:27.326057Z","iopub.status.idle":"2022-07-31T22:33:27.357147Z","shell.execute_reply.started":"2022-07-31T22:33:27.326017Z","shell.execute_reply":"2022-07-31T22:33:27.356116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"L=[]\nfor i in Data.columns:\n    if(len(list(Data[i].drop_duplicates()))<8):\n        L.append(i)\nL=L[:42] \nfig, ax = plt.subplots(6,3,figsize=(20,20))\nz=1\nL1=L[:18]\nfor i in L1:\n    plt.subplot(6,3,z)\n    Data[['SalePrice',i]].groupby([i],as_index=False).sum().sort_values(by='SalePrice',ascending=False)\n    sns.barplot(x =i, y ='SalePrice', data = Data,\n            palette ='plasma')\n    z=z+1","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:27.359088Z","iopub.execute_input":"2022-07-31T22:33:27.361287Z","iopub.status.idle":"2022-07-31T22:33:31.920792Z","shell.execute_reply.started":"2022-07-31T22:33:27.361257Z","shell.execute_reply":"2022-07-31T22:33:31.919674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"L2=L[18:]    \nfig, ax = plt.subplots(6,4,figsize=(26,27))\nz=1\nfor i in L2:\n    plt.subplot(6,4,z)\n    Data[['SalePrice',i]].groupby([i],as_index=False).sum().sort_values(by='SalePrice',ascending=False)\n    sns.barplot(x =i, y ='SalePrice', data = Data,\n            palette ='plasma')\n    z=z+1","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:31.923138Z","iopub.execute_input":"2022-07-31T22:33:31.923541Z","iopub.status.idle":"2022-07-31T22:33:38.326014Z","shell.execute_reply.started":"2022-07-31T22:33:31.923493Z","shell.execute_reply":"2022-07-31T22:33:38.325058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grid = sns.FacetGrid(Data, row='GarageFinish', col='Fireplaces', size=2.2, aspect=1.6)\ngrid.map(sns.barplot ,'SalePrice', 'KitchenQual',alpha=.9).add_legend()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:38.327724Z","iopub.execute_input":"2022-07-31T22:33:38.328356Z","iopub.status.idle":"2022-07-31T22:33:41.644079Z","shell.execute_reply.started":"2022-07-31T22:33:38.328315Z","shell.execute_reply":"2022-07-31T22:33:41.643122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grid = sns.FacetGrid(Data, row='FullBath', col='HalfBath', size=2.2, aspect=1.6)\ngrid.map(sns.barplot ,'KitchenAbvGr', 'SalePrice',alpha=.9).add_legend()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:41.646725Z","iopub.execute_input":"2022-07-31T22:33:41.648650Z","iopub.status.idle":"2022-07-31T22:33:43.720863Z","shell.execute_reply.started":"2022-07-31T22:33:41.648608Z","shell.execute_reply":"2022-07-31T22:33:43.719803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grid = sns.FacetGrid(Data, row='Utilities', col='LandContour', size=2.2, aspect=1.6)\ngrid.map(sns.barplot ,'SalePrice', 'LandSlope',alpha=.9).add_legend()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:43.722228Z","iopub.execute_input":"2022-07-31T22:33:43.722865Z","iopub.status.idle":"2022-07-31T22:33:46.330008Z","shell.execute_reply.started":"2022-07-31T22:33:43.722822Z","shell.execute_reply":"2022-07-31T22:33:46.329036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grid = sns.FacetGrid(Data, row='Alley', col='LotShape', size=2.2, aspect=1.6)\ngrid.map(sns.barplot ,'SalePrice', 'LandContour',alpha=.9).add_legend()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:46.334309Z","iopub.execute_input":"2022-07-31T22:33:46.337072Z","iopub.status.idle":"2022-07-31T22:33:48.419955Z","shell.execute_reply.started":"2022-07-31T22:33:46.337022Z","shell.execute_reply":"2022-07-31T22:33:48.418815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.info()","metadata":{"papermill":{"duration":0.059404,"end_time":"2022-07-21T19:16:36.092957","exception":false,"start_time":"2022-07-21T19:16:36.033553","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-07-31T22:33:48.424616Z","iopub.execute_input":"2022-07-31T22:33:48.427352Z","iopub.status.idle":"2022-07-31T22:33:48.458793Z","shell.execute_reply.started":"2022-07-31T22:33:48.427308Z","shell.execute_reply":"2022-07-31T22:33:48.457845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.describe()","metadata":{"papermill":{"duration":0.156039,"end_time":"2022-07-21T19:16:36.260268","exception":false,"start_time":"2022-07-21T19:16:36.104229","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-07-31T22:33:48.462992Z","iopub.execute_input":"2022-07-31T22:33:48.465726Z","iopub.status.idle":"2022-07-31T22:33:48.602677Z","shell.execute_reply.started":"2022-07-31T22:33:48.465684Z","shell.execute_reply":"2022-07-31T22:33:48.601680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(25, 25))\nsns.heatmap(Data.corr(), annot = True,cmap= 'Blues')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:48.607181Z","iopub.execute_input":"2022-07-31T22:33:48.610069Z","iopub.status.idle":"2022-07-31T22:33:56.200268Z","shell.execute_reply.started":"2022-07-31T22:33:48.610012Z","shell.execute_reply":"2022-07-31T22:33:56.199418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:56.204671Z","iopub.execute_input":"2022-07-31T22:33:56.205588Z","iopub.status.idle":"2022-07-31T22:33:56.213312Z","shell.execute_reply.started":"2022-07-31T22:33:56.205545Z","shell.execute_reply":"2022-07-31T22:33:56.212492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nData.drop(['1stFlrSF','GarageArea','GarageYrBlt'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:56.214640Z","iopub.execute_input":"2022-07-31T22:33:56.215503Z","iopub.status.idle":"2022-07-31T22:33:56.227505Z","shell.execute_reply.started":"2022-07-31T22:33:56.215464Z","shell.execute_reply":"2022-07-31T22:33:56.226471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.iloc[:,:40].plot.box(figsize=(17,4))\n","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-31T22:33:56.228939Z","iopub.execute_input":"2022-07-31T22:33:56.230030Z","iopub.status.idle":"2022-07-31T22:33:56.555260Z","shell.execute_reply.started":"2022-07-31T22:33:56.229913Z","shell.execute_reply":"2022-07-31T22:33:56.554262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.iloc[:,40:60].plot.box(figsize=(17,4))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:56.557693Z","iopub.execute_input":"2022-07-31T22:33:56.558442Z","iopub.status.idle":"2022-07-31T22:33:56.903423Z","shell.execute_reply.started":"2022-07-31T22:33:56.558399Z","shell.execute_reply":"2022-07-31T22:33:56.902442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.iloc[:,60:].plot.box(figsize=(17,4))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:56.904802Z","iopub.execute_input":"2022-07-31T22:33:56.905718Z","iopub.status.idle":"2022-07-31T22:33:57.281741Z","shell.execute_reply.started":"2022-07-31T22:33:56.905678Z","shell.execute_reply":"2022-07-31T22:33:57.279776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Removing outlier\nnumeric_list=Data.select_dtypes(exclude='object').columns\nfor i in numeric_list:\n    \n    # IQR\n    Q1 = np.percentile(Data.loc[:, i],25)\n    Q3 = np.percentile(Data.loc[:, i],75)\n    \n    IQR = Q3 - Q1\n    \n    print(\"Old shape: \", Data.loc[:, i].shape)\n    \n    # upper bound\n    upper = np.where(Data.loc[:, i] >= (Q3 +2*IQR))\n    \n    # lower bound\n    lower = np.where(Data.loc[:, i] <= (Q1 - 2*IQR))\n    \n    print(\"{} -- {}\".format(upper, lower))\n    \n    try:\n        Data.drop(upper[0], inplace = True)\n    except: print(\"KeyError: {} not found in axis\".format(upper[0]))\n    \n    try:\n        Data.drop(lower[0], inplace = True)\n    except:  print(\"KeyError: {} not found in axis\".format(lower[0]))\n        \n    print(\"New shape: \", Data.shape)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:57.286131Z","iopub.execute_input":"2022-07-31T22:33:57.288955Z","iopub.status.idle":"2022-07-31T22:33:57.429074Z","shell.execute_reply.started":"2022-07-31T22:33:57.288914Z","shell.execute_reply":"2022-07-31T22:33:57.428120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.iloc[:,:32].plot.box(figsize=(17,4))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:57.433311Z","iopub.execute_input":"2022-07-31T22:33:57.434116Z","iopub.status.idle":"2022-07-31T22:33:57.767807Z","shell.execute_reply.started":"2022-07-31T22:33:57.434075Z","shell.execute_reply":"2022-07-31T22:33:57.766907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.iloc[:,32:46].plot.box(figsize=(17,4))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:57.772396Z","iopub.execute_input":"2022-07-31T22:33:57.773026Z","iopub.status.idle":"2022-07-31T22:33:58.094772Z","shell.execute_reply.started":"2022-07-31T22:33:57.772987Z","shell.execute_reply":"2022-07-31T22:33:58.093743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.iloc[:,46:55].plot.box(figsize=(17,4))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:58.099278Z","iopub.execute_input":"2022-07-31T22:33:58.102087Z","iopub.status.idle":"2022-07-31T22:33:58.397959Z","shell.execute_reply.started":"2022-07-31T22:33:58.102044Z","shell.execute_reply":"2022-07-31T22:33:58.396975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.iloc[:,55:].plot.box(figsize=(17,4))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:58.402428Z","iopub.execute_input":"2022-07-31T22:33:58.405112Z","iopub.status.idle":"2022-07-31T22:33:58.873934Z","shell.execute_reply.started":"2022-07-31T22:33:58.405069Z","shell.execute_reply":"2022-07-31T22:33:58.872849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{"papermill":{"duration":0.02009,"end_time":"2022-07-21T19:16:43.350095","exception":false,"start_time":"2022-07-21T19:16:43.330005","status":"completed"},"tags":[]}},{"cell_type":"code","source":"print('Data Shape = ',Data.shape)\nencode_columns = list(Data.select_dtypes(exclude='object').columns)\nData_coorr=[]\nDrop_col=[]\nfor i in encode_columns:\n    if((Data[i].corr(Data['SalePrice']) <= 0.07) and (Data[i].corr(Data['SalePrice'])>= -0.07)):\n        #New_Data.drop(i, axis=1, inplace=True)\n        Drop_col.append(i)\n        print(i)\n    elif((Data[i].corr(Data['SalePrice']) >= 0.3) or (Data[i].corr(Data['SalePrice'])<= -0.3)):\n         Data_coorr.append([Data['SalePrice'].corr(Data[i]),i])","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:58.878445Z","iopub.execute_input":"2022-07-31T22:33:58.880385Z","iopub.status.idle":"2022-07-31T22:33:58.941775Z","shell.execute_reply.started":"2022-07-31T22:33:58.880328Z","shell.execute_reply":"2022-07-31T22:33:58.940430Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nD=Data\nx=D.loc[:,Drop_col]\n\nmodel = PCA(n_components= 1, svd_solver='full')#it can be full,arpack,randomized\nmodel.fit(x)\n\ndata = model.transform(x)\ndata = pd.DataFrame(data)\n\nData = pd.concat([Data, data], axis=1)\nData.drop(Drop_col, axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:58.946381Z","iopub.execute_input":"2022-07-31T22:33:58.948861Z","iopub.status.idle":"2022-07-31T22:33:58.997694Z","shell.execute_reply.started":"2022-07-31T22:33:58.948818Z","shell.execute_reply":"2022-07-31T22:33:58.996464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.003118Z","iopub.execute_input":"2022-07-31T22:33:59.005868Z","iopub.status.idle":"2022-07-31T22:33:59.068099Z","shell.execute_reply.started":"2022-07-31T22:33:59.005804Z","shell.execute_reply":"2022-07-31T22:33:59.067053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Nulls = Data.isnull().sum().sort_values(ascending=False)\npercent = (Data.isnull().sum()/Data.isnull().count()).sort_values(ascending=False)\nmissing_data = pd.concat([Nulls, percent], axis=1, keys=['Nulls', 'Percent'])\nprint(missing_data[:40])\nmissing_data=missing_data[missing_data['Nulls']>=344]\nprint(missing_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.072883Z","iopub.execute_input":"2022-07-31T22:33:59.075481Z","iopub.status.idle":"2022-07-31T22:33:59.138343Z","shell.execute_reply.started":"2022-07-31T22:33:59.075436Z","shell.execute_reply":"2022-07-31T22:33:59.137315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_data.index","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.143308Z","iopub.execute_input":"2022-07-31T22:33:59.145801Z","iopub.status.idle":"2022-07-31T22:33:59.157684Z","shell.execute_reply.started":"2022-07-31T22:33:59.145759Z","shell.execute_reply":"2022-07-31T22:33:59.156425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nData = Data.drop((missing_data).index,axis=1)\n\nNul=Data.isnull().sum().sort_values(ascending=False)\nprint(Nul[:20])","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.162746Z","iopub.execute_input":"2022-07-31T22:33:59.164037Z","iopub.status.idle":"2022-07-31T22:33:59.189851Z","shell.execute_reply.started":"2022-07-31T22:33:59.163996Z","shell.execute_reply":"2022-07-31T22:33:59.188854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def label_encode_columns(df, columns):\n    encoders = {}\n    for col in columns:\n        le = LabelEncoder().fit(df[col])\n        df[col] = le.transform(df[col])\n        encoders[col] = le\n    return df, encoders","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.194329Z","iopub.execute_input":"2022-07-31T22:33:59.196901Z","iopub.status.idle":"2022-07-31T22:33:59.204685Z","shell.execute_reply.started":"2022-07-31T22:33:59.196860Z","shell.execute_reply":"2022-07-31T22:33:59.203501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"encode_columns = list(Data.select_dtypes(['object']).columns)\ncol=Data.columns\nData, encoders = label_encode_columns(df=Data, columns=encode_columns)\n\n\nprint('Updates dataframe is : \\n' ,Data )\n \ncol=list(Data.columns)\nprint(col)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.206588Z","iopub.execute_input":"2022-07-31T22:33:59.207377Z","iopub.status.idle":"2022-07-31T22:33:59.287064Z","shell.execute_reply.started":"2022-07-31T22:33:59.207324Z","shell.execute_reply":"2022-07-31T22:33:59.286058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.295907Z","iopub.execute_input":"2022-07-31T22:33:59.296632Z","iopub.status.idle":"2022-07-31T22:33:59.346090Z","shell.execute_reply.started":"2022-07-31T22:33:59.296591Z","shell.execute_reply":"2022-07-31T22:33:59.345089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imp = SimpleImputer(missing_values=np.NAN, strategy='mean')\nimp = imp.fit(Data)\nData = imp.transform(Data)\nData= np.reshape(Data,(len(Data),len(Data[0])))\nData = pd.DataFrame(Data,columns=col)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.347755Z","iopub.execute_input":"2022-07-31T22:33:59.348439Z","iopub.status.idle":"2022-07-31T22:33:59.369431Z","shell.execute_reply.started":"2022-07-31T22:33:59.348399Z","shell.execute_reply":"2022-07-31T22:33:59.368394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.371040Z","iopub.execute_input":"2022-07-31T22:33:59.371704Z","iopub.status.idle":"2022-07-31T22:33:59.380144Z","shell.execute_reply.started":"2022-07-31T22:33:59.371665Z","shell.execute_reply":"2022-07-31T22:33:59.378884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y=Data.loc[:,'SalePrice']\nX=Data.drop('SalePrice',axis=1)\n","metadata":{"papermill":{"duration":0.048841,"end_time":"2022-07-21T19:16:54.761539","exception":false,"start_time":"2022-07-21T19:16:54.712698","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-07-31T22:33:59.382320Z","iopub.execute_input":"2022-07-31T22:33:59.383153Z","iopub.status.idle":"2022-07-31T22:33:59.391231Z","shell.execute_reply.started":"2022-07-31T22:33:59.383113Z","shell.execute_reply":"2022-07-31T22:33:59.389647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test_Data = pd.read_csv(r'../input/house-prices-advanced-regression-techniques/test.csv')\nTest_Data.info()","metadata":{"papermill":{"duration":0.080546,"end_time":"2022-07-21T19:16:54.954509","exception":false,"start_time":"2022-07-21T19:16:54.873963","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-07-31T22:33:59.393293Z","iopub.execute_input":"2022-07-31T22:33:59.394167Z","iopub.status.idle":"2022-07-31T22:33:59.453076Z","shell.execute_reply.started":"2022-07-31T22:33:59.394128Z","shell.execute_reply":"2022-07-31T22:33:59.452059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Nuls = Test_Data.isnull().sum().sort_values(ascending=False)\nprint(Nuls[:20])","metadata":{"papermill":{"duration":0.059515,"end_time":"2022-07-21T19:16:55.051944","exception":false,"start_time":"2022-07-21T19:16:54.992429","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-07-31T22:33:59.454711Z","iopub.execute_input":"2022-07-31T22:33:59.455389Z","iopub.status.idle":"2022-07-31T22:33:59.474748Z","shell.execute_reply.started":"2022-07-31T22:33:59.455333Z","shell.execute_reply":"2022-07-31T22:33:59.473601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test_Data[Drop_col].describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.476376Z","iopub.execute_input":"2022-07-31T22:33:59.477009Z","iopub.status.idle":"2022-07-31T22:33:59.528358Z","shell.execute_reply.started":"2022-07-31T22:33:59.476969Z","shell.execute_reply":"2022-07-31T22:33:59.527346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test_Data[Drop_col].info()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.530153Z","iopub.execute_input":"2022-07-31T22:33:59.530815Z","iopub.status.idle":"2022-07-31T22:33:59.546278Z","shell.execute_reply.started":"2022-07-31T22:33:59.530774Z","shell.execute_reply":"2022-07-31T22:33:59.545380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test_Data['BsmtHalfBath'].fillna((Test_Data['BsmtHalfBath'].mean()),inplace=True)\nTest_Data['BsmtFinSF2'].fillna((Test_Data['BsmtFinSF2'].mean()),inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.547809Z","iopub.execute_input":"2022-07-31T22:33:59.548169Z","iopub.status.idle":"2022-07-31T22:33:59.555810Z","shell.execute_reply.started":"2022-07-31T22:33:59.548132Z","shell.execute_reply":"2022-07-31T22:33:59.554575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nDa=Test_Data\nx=Da.loc[:,Drop_col]\n\nmodel = PCA(n_components= 1, svd_solver='full')#it can be full,arpack,randomized\nmodel.fit(x)\n\ndata = model.transform(x)\ndata = pd.DataFrame(data)\n\nTest_Data = pd.concat([Test_Data, data], axis=1)\nTest_Data.drop(Drop_col, axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.557777Z","iopub.execute_input":"2022-07-31T22:33:59.558344Z","iopub.status.idle":"2022-07-31T22:33:59.606724Z","shell.execute_reply.started":"2022-07-31T22:33:59.558302Z","shell.execute_reply":"2022-07-31T22:33:59.605414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Nulls = Test_Data.isnull().sum().sort_values(ascending=False)\npercent = (Test_Data.isnull().sum()/Test_Data.isnull().count()).sort_values(ascending=False)\nmissing_data = pd.concat([Nulls, percent], axis=1, keys=['Nulls', 'Percent'])\nprint(missing_data[:40])\nmissing_data=missing_data[missing_data['Nulls']>=100]\nprint(missing_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.612307Z","iopub.execute_input":"2022-07-31T22:33:59.616145Z","iopub.status.idle":"2022-07-31T22:33:59.711482Z","shell.execute_reply.started":"2022-07-31T22:33:59.616096Z","shell.execute_reply":"2022-07-31T22:33:59.710435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test_Data = Test_Data.drop((missing_data).index,1)\n\nNul=Test_Data.isnull().sum().sort_values(ascending=False)\nprint(Nul[:20])","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.713383Z","iopub.execute_input":"2022-07-31T22:33:59.714086Z","iopub.status.idle":"2022-07-31T22:33:59.731465Z","shell.execute_reply.started":"2022-07-31T22:33:59.714045Z","shell.execute_reply":"2022-07-31T22:33:59.730499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"encode_columns = list(Test_Data.select_dtypes(['object']).columns)\ncol=Test_Data.columns\nTest_Data, encoders = label_encode_columns(df=Test_Data, columns=encode_columns)\n\n\nprint('Updates dataframe is : \\n' ,Test_Data )\n \ncol=list(Test_Data.columns)\nprint(col)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.733018Z","iopub.execute_input":"2022-07-31T22:33:59.733393Z","iopub.status.idle":"2022-07-31T22:33:59.790883Z","shell.execute_reply.started":"2022-07-31T22:33:59.733340Z","shell.execute_reply":"2022-07-31T22:33:59.789988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imp = SimpleImputer(missing_values=np.NAN, strategy='mean')\nimp = imp.fit(Test_Data)\nX_Test = imp.transform(Test_Data)\nX_Test= np.reshape(X_Test,(len(X_Test),len(X_Test[0])))\nX_Test = pd.DataFrame(X_Test,columns=col)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.793489Z","iopub.execute_input":"2022-07-31T22:33:59.794207Z","iopub.status.idle":"2022-07-31T22:33:59.809494Z","shell.execute_reply.started":"2022-07-31T22:33:59.794163Z","shell.execute_reply":"2022-07-31T22:33:59.808516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_Test=X_Test.loc[:,X.columns]","metadata":{"papermill":{"duration":0.124338,"end_time":"2022-07-21T19:16:55.213769","exception":false,"start_time":"2022-07-21T19:16:55.089431","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-07-31T22:33:59.811354Z","iopub.execute_input":"2022-07-31T22:33:59.811889Z","iopub.status.idle":"2022-07-31T22:33:59.818223Z","shell.execute_reply.started":"2022-07-31T22:33:59.811851Z","shell.execute_reply":"2022-07-31T22:33:59.817026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.819925Z","iopub.execute_input":"2022-07-31T22:33:59.820323Z","iopub.status.idle":"2022-07-31T22:33:59.832251Z","shell.execute_reply.started":"2022-07-31T22:33:59.820286Z","shell.execute_reply":"2022-07-31T22:33:59.831211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Read sample_submission Data***","metadata":{"papermill":{"duration":0.038403,"end_time":"2022-07-21T19:16:55.290753","exception":false,"start_time":"2022-07-21T19:16:55.252350","status":"completed"},"tags":[]}},{"cell_type":"code","source":"Test_Data = pd.read_csv(r'../input/house-prices-advanced-regression-techniques/sample_submission.csv',skiprows= 0)\nprint(Test_Data)\nVD=Test_Data.iloc[:,1]\n\nprint(VD.shape)","metadata":{"papermill":{"duration":0.114936,"end_time":"2022-07-21T19:16:55.458106","exception":false,"start_time":"2022-07-21T19:16:55.343170","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-07-31T22:33:59.833905Z","iopub.execute_input":"2022-07-31T22:33:59.834314Z","iopub.status.idle":"2022-07-31T22:33:59.850880Z","shell.execute_reply.started":"2022-07-31T22:33:59.834277Z","shell.execute_reply":"2022-07-31T22:33:59.849530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LinearRegression\nfrom sklearn.svm import SVR\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.linear_model import Ridge\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.metrics import mean_squared_error \nfrom sklearn.metrics import accuracy_score","metadata":{"papermill":{"duration":460.847372,"end_time":"2022-07-21T19:24:36.500962","exception":false,"start_time":"2022-07-21T19:16:55.653590","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"LR = SVR()\nLR.fit(X,y)\nprint('SVR')\n\nprint('score = ',LR.score(X,y))\nVD_predict4=LR.predict(X_Test)\nMSEValue = mean_squared_error(VD, VD_predict4, multioutput='uniform_average')\nprint('Mean_squared_error = ',MSEValue)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:33:59.854209Z","iopub.execute_input":"2022-07-31T22:33:59.854574Z","iopub.status.idle":"2022-07-31T22:34:00.497377Z","shell.execute_reply.started":"2022-07-31T22:33:59.854541Z","shell.execute_reply":"2022-07-31T22:34:00.496347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"LR = SVR(C=650)#C=650\nLR.fit(X,y)\nprint('SVR')\n\nprint('score = ',LR.score(X,y))\nVD_predict6=LR.predict(X_Test)\nMSEValue = mean_squared_error(VD, VD_predict4, multioutput='uniform_average')\nprint('Mean_squared_error = ',MSEValue)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:34:28.598551Z","iopub.execute_input":"2022-07-31T22:34:28.599241Z","iopub.status.idle":"2022-07-31T22:34:29.252833Z","shell.execute_reply.started":"2022-07-31T22:34:28.599198Z","shell.execute_reply":"2022-07-31T22:34:29.251765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DTR = DecisionTreeRegressor(random_state=True)\nDTR.fit(X,y)\nprint('DecisionTreeRegressor')\nprint('score = ',DTR.score(X,y))\nVD_predict2=DTR.predict(X_Test)\nMSEValue = mean_squared_error(VD, VD_predict2, multioutput='uniform_average')\nprint('Mean_squared_error = ',MSEValue)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:34:01.163025Z","iopub.execute_input":"2022-07-31T22:34:01.163498Z","iopub.status.idle":"2022-07-31T22:34:01.204434Z","shell.execute_reply.started":"2022-07-31T22:34:01.163458Z","shell.execute_reply":"2022-07-31T22:34:01.203323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"RFR = RandomForestRegressor(random_state=True)\nRFR.fit(X,y)\nprint('RandomForestRegressor')\nprint('score = ',RFR.score(X,y))\nVD_predict1=RFR.predict(X_Test)\nMSEValue = mean_squared_error(VD, VD_predict1, multioutput='uniform_average')\nprint('Mean_squared_error = ',MSEValue)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:34:01.206001Z","iopub.execute_input":"2022-07-31T22:34:01.206401Z","iopub.status.idle":"2022-07-31T22:34:02.959990Z","shell.execute_reply.started":"2022-07-31T22:34:01.206348Z","shell.execute_reply":"2022-07-31T22:34:02.957952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"VD_predict1","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:34:02.961572Z","iopub.execute_input":"2022-07-31T22:34:02.961951Z","iopub.status.idle":"2022-07-31T22:34:02.970042Z","shell.execute_reply.started":"2022-07-31T22:34:02.961913Z","shell.execute_reply":"2022-07-31T22:34:02.969101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"LR = LinearRegression(n_jobs=-1)\nLR.fit(X,y)\n\nprint('LinearRegression')\n\nprint('score = ',LR.score(X,y))\nVD_predict3=LR.predict(X_Test)\nMSEValue = mean_squared_error(VD, VD_predict3, multioutput='uniform_average')\nprint('Mean_squared_error = ',MSEValue)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:34:02.971529Z","iopub.execute_input":"2022-07-31T22:34:02.971904Z","iopub.status.idle":"2022-07-31T22:34:03.001810Z","shell.execute_reply.started":"2022-07-31T22:34:02.971866Z","shell.execute_reply":"2022-07-31T22:34:03.000706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# We Can Also Use cross_val_score ","metadata":{"papermill":{"duration":0.054026,"end_time":"2022-07-21T19:24:36.634716","exception":false,"start_time":"2022-07-21T19:24:36.580690","status":"completed"},"tags":[]}},{"cell_type":"code","source":"'''\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.svm import SVR\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.linear_model import Ridge\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.metrics import mean_squared_error \nfrom sklearn.metrics import accuracy_score\n\nparams=[{'fit_intercept':(True,False)},\n            {'min_samples_split':[6,8,12],\n             'max_depth':[5,10,20]},\n             {'n_estimators':[50,150,100],\n             'max_depth':[5,10,15]},\n             {'alpha': [0.1,700,10,500,200]}]\n#kernel{‘linear’, ‘poly’, ‘rbf’, ‘sigmoid’, ‘precomputed’\nLR = LinearRegression(copy_X=True)\nDTR = DecisionTreeRegressor()\nRFR = RandomForestRegressor()\nRM = Ridge()\n\nmodels=[LR,DTR,RFR,RM]\n\nfor model,param in zip(models,params):\n    print('Model is ',model)\n    for i in range (3,11):\n        GridSearchModel = GridSearchCV(model,param, cv = i,return_train_score=True, n_jobs=-1)\n        GridSearchModel.fit(X, y)\n        VD_predict=GridSearchModel.predict(X_Test)\n\n        MSEValue = mean_squared_error(VD, VD_predict, multioutput='uniform_average') \n        \n        sorted(GridSearchModel.cv_results_.keys())\n        #accuracy = accuracy_score(ViD, CVS_prediction, normalize=False)\n        #GridSearchResults = pd.DataFrame(GridSearchModel.cv_results_)[['mean_test_score', 'std_test_score', 'params' , 'rank_test_score' , 'mean_fit_time']]\n        print('CV = ',i)\n# Showing Results\n        #print('All Results are :\\n', GridSearchResults )\n        print('Best Score is :', GridSearchModel.best_score_)\n        print('Best Parameters are :', GridSearchModel.best_params_)\n        print('Mean_squared_error = ',MSEValue)\n        print(VD_predict[:5])\n        #print('Best Estimator is :', GridSearchModel.best_estimator_)\n        print('---------------------------')\n    print('\\t\\t**********************************************************')\n\n'''","metadata":{"execution":{"iopub.status.busy":"2022-07-31T22:34:03.006874Z","iopub.execute_input":"2022-07-31T22:34:03.007601Z","iopub.status.idle":"2022-07-31T22:34:03.031935Z","shell.execute_reply.started":"2022-07-31T22:34:03.007555Z","shell.execute_reply":"2022-07-31T22:34:03.030817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'''\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.svm import SVR\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.model_selection import cross_val_score\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.metrics import mean_squared_error \n\n\n\nLR = LinearRegression()\nSV = SVR(gamma = 'auto')\nDTR = DecisionTreeRegressor()\nRFR = RandomForestRegressor(n_estimators = 100)\n\n\nmodels = [LR , SV , DTR , RFR]\n\nfor m in models:\n    for n in range(2,11):\n        ViD=VD\n        CVS=cross_val_score(m, X, y, cv=n,n_jobs=-1)   \n        print('Score of model ' ,m ,' = ',m.score(X, y))\n        print('result of model : ' , m ,' for cv value ',n,' is ' ,np.mean(CVS) )\n        print('-----------------------------------')\n    \n    print('=====================================')\n    print('=====================================')\n    \n'''","metadata":{"papermill":{"duration":0.054716,"end_time":"2022-07-21T19:24:36.730134","exception":false,"start_time":"2022-07-21T19:24:36.675418","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-07-31T22:34:03.037809Z","iopub.execute_input":"2022-07-31T22:34:03.040959Z","iopub.status.idle":"2022-07-31T22:34:03.058079Z","shell.execute_reply.started":"2022-07-31T22:34:03.040909Z","shell.execute_reply":"2022-07-31T22:34:03.056827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test_Data = pd.read_csv(r'../input/house-prices-advanced-regression-techniques/sample_submission.csv',skiprows= 0)\nsub = {'Id': Test_Data.Id, 'SalePrice': VD_predict6}\nbasic_sub = pd.DataFrame(data=sub)\nbasic_sub.to_csv(\"submission.csv\", index=False)","metadata":{"papermill":{"duration":0.079187,"end_time":"2022-07-21T19:24:36.981839","exception":false,"start_time":"2022-07-21T19:24:36.902652","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-07-31T22:34:52.082256Z","iopub.execute_input":"2022-07-31T22:34:52.082721Z","iopub.status.idle":"2022-07-31T22:34:52.104048Z","shell.execute_reply.started":"2022-07-31T22:34:52.082683Z","shell.execute_reply":"2022-07-31T22:34:52.103127Z"},"trusted":true},"execution_count":null,"outputs":[]}]}