{"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":"# !kaggle competitions download -c house-prices-advanced-regression-techniques","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:23:24.998307Z","iopub.execute_input":"2022-07-29T10:23:24.999357Z","iopub.status.idle":"2022-07-29T10:23:25.004744Z","shell.execute_reply.started":"2022-07-29T10:23:24.999320Z","shell.execute_reply":"2022-07-29T10:23:25.003229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# from zipfile import ZipFile","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:23:25.007414Z","iopub.execute_input":"2022-07-29T10:23:25.008275Z","iopub.status.idle":"2022-07-29T10:23:25.018799Z","shell.execute_reply.started":"2022-07-29T10:23:25.008225Z","shell.execute_reply":"2022-07-29T10:23:25.017619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# with ZipFile('house-prices-advanced-regression-techniques.zip', 'r') as zipObj:\n#    zipObj.extractall()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:23:25.021054Z","iopub.execute_input":"2022-07-29T10:23:25.021874Z","iopub.status.idle":"2022-07-29T10:23:25.032089Z","shell.execute_reply.started":"2022-07-29T10:23:25.021830Z","shell.execute_reply":"2022-07-29T10:23:25.030856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:23:25.033276Z","iopub.execute_input":"2022-07-29T10:23:25.034174Z","iopub.status.idle":"2022-07-29T10:23:25.681296Z","shell.execute_reply.started":"2022-07-29T10:23:25.034139Z","shell.execute_reply":"2022-07-29T10:23:25.680093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_theme()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:23:25.683798Z","iopub.execute_input":"2022-07-29T10:23:25.684135Z","iopub.status.idle":"2022-07-29T10:23:25.689307Z","shell.execute_reply.started":"2022-07-29T10:23:25.684104Z","shell.execute_reply":"2022-07-29T10:23:25.688347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('../input/house-prices-advanced-regression-techniques/train.csv')\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:23:25.690860Z","iopub.execute_input":"2022-07-29T10:23:25.691722Z","iopub.status.idle":"2022-07-29T10:23:25.791603Z","shell.execute_reply.started":"2022-07-29T10:23:25.691690Z","shell.execute_reply":"2022-07-29T10:23:25.790411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:23:25.792737Z","iopub.execute_input":"2022-07-29T10:23:25.793057Z","iopub.status.idle":"2022-07-29T10:23:25.910554Z","shell.execute_reply.started":"2022-07-29T10:23:25.793029Z","shell.execute_reply":"2022-07-29T10:23:25.909493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"scrolled":true,"tags":[],"execution":{"iopub.status.busy":"2022-07-29T10:23:25.912344Z","iopub.execute_input":"2022-07-29T10:23:25.913048Z","iopub.status.idle":"2022-07-29T10:23:25.944104Z","shell.execute_reply.started":"2022-07-29T10:23:25.912995Z","shell.execute_reply":"2022-07-29T10:23:25.942925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install feature_engine","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:11.692105Z","iopub.execute_input":"2022-07-29T10:24:11.692554Z","iopub.status.idle":"2022-07-29T10:24:11.698156Z","shell.execute_reply.started":"2022-07-29T10:24:11.692504Z","shell.execute_reply":"2022-07-29T10:24:11.696715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from feature_engine.selection import DropDuplicateFeatures, DropConstantFeatures, DropCorrelatedFeatures","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:29.573937Z","iopub.execute_input":"2022-07-29T10:24:29.574396Z","iopub.status.idle":"2022-07-29T10:24:29.580382Z","shell.execute_reply.started":"2022-07-29T10:24:29.574363Z","shell.execute_reply":"2022-07-29T10:24:29.578922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = pd.read_csv('../input/house-prices-advanced-regression-techniques/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:29.595692Z","iopub.execute_input":"2022-07-29T10:24:29.596123Z","iopub.status.idle":"2022-07-29T10:24:29.637104Z","shell.execute_reply.started":"2022-07-29T10:24:29.596089Z","shell.execute_reply":"2022-07-29T10:24:29.635936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"column_greater_700_nulls = train_df.isna().sum() > 700\ncolumn_greater_700_nulls_test = test_df.isna().sum() > 700\ncols_to_del = set()\nfor index, value in column_greater_700_nulls.items():\n    if value:\n        cols_to_del.add(index)\nfor index, value in column_greater_700_nulls_test.items():\n    if value:\n        cols_to_del.add(index)\n        \ncolumns_isna = (train_df.isna().sum() != 0) & (train_df.isna().sum() <= 700)\ncolumns_isna_test = (test_df.isna().sum() != 0) & (test_df.isna().sum() <= 700)\ncols_na = set()\nfor index, value in columns_isna.items():\n    if value:\n        cols_na.add(index)\nfor index, value in columns_isna_test.items():\n    if value:\n        cols_na.add(index)\ncols_na = cols_na.difference(cols_to_del)\n        \ncat_cols = set()\nfor col in train_df.columns:\n    if train_df[col].dtype == 'object':\n        cat_cols.add(col)","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:29.639238Z","iopub.execute_input":"2022-07-29T10:24:29.639620Z","iopub.status.idle":"2022-07-29T10:24:29.709387Z","shell.execute_reply.started":"2022-07-29T10:24:29.639584Z","shell.execute_reply":"2022-07-29T10:24:29.707413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df_mean = {}\ntrain_df_mode = {}\ntrain_df_median = {}\ncols_to_del_2 = set()\ncols_to_del_3 = set()\n\nfor col in cols_na:\n    if train_df[col].dtype == 'float64':\n        train_df_mean[col] = train_df[col].mean()\n    elif train_df[col].dtype == 'object':\n        train_df_mode[col] = train_df[col].mode()[0]\n    elif train_df[col].dtype == 'int64':\n        train_df_median[col] = train_df[col].median()\n\ncols_const = DropConstantFeatures(tol=0.99, variables=None)\ncols_dupl = DropDuplicateFeatures(variables=None)\ncols_corr = DropCorrelatedFeatures(threshold=0.85, method='pearson')","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:29.711599Z","iopub.execute_input":"2022-07-29T10:24:29.712758Z","iopub.status.idle":"2022-07-29T10:24:29.734269Z","shell.execute_reply.started":"2022-07-29T10:24:29.712711Z","shell.execute_reply":"2022-07-29T10:24:29.733403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\"\"\"\n1 - drop > 700\n2 - fillna\n3 - get dummies\n4 - drop\n\"\"\"\ndef clean_data(df, test=False):\n    global cols_to_del, cat_cols, train_df_mean, train_df_mode, cols_const, cols_dupl, cols_corr, cols_to_del_2, cols_to_del_3\n    df.drop(columns=['Id'], inplace=True, axis=1)\n    df.drop(columns=cols_to_del, inplace=True, axis=1)\n    for col in train_df_mean:\n        df[col].fillna(train_df_mean[col], inplace=True)\n    for col in train_df_mode:\n        df[col].fillna(train_df_mode[col], inplace=True)\n    for col in train_df_median:\n        df[col].fillna(train_df_median[col], inplace=True)\n    df = pd.get_dummies(df, drop_first=True)\n    if not test:\n        cols_const.fit(df)\n        cols_to_del_2 = cols_to_del_2.union(cols_const.features_to_drop_)\n        cols_dupl.fit(df)\n        cols_to_del_2 = cols_to_del_2.union(cols_dupl.features_to_drop_)\n        cols_corr.fit(df)\n        cols_to_del_2 = cols_to_del_2.union(cols_corr.features_to_drop_)\n    if test:\n        for col in cols_to_del_2:\n            if col in df.columns:\n                cols_to_del_3.add(col)\n    df.drop(columns=cols_to_del_3, inplace=True, axis=1)\n    return df","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:29.737787Z","iopub.execute_input":"2022-07-29T10:24:29.738779Z","iopub.status.idle":"2022-07-29T10:24:29.752208Z","shell.execute_reply.started":"2022-07-29T10:24:29.738729Z","shell.execute_reply":"2022-07-29T10:24:29.751067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = clean_data(train_df)\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:29.753612Z","iopub.execute_input":"2022-07-29T10:24:29.754708Z","iopub.status.idle":"2022-07-29T10:24:31.749441Z","shell.execute_reply.started":"2022-07-29T10:24:29.754663Z","shell.execute_reply":"2022-07-29T10:24:31.748358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA","metadata":{"tags":[]}},{"cell_type":"code","source":"plt.figure(figsize=(20,8))\nplt.title('Distribution of SalePrice')\nsns.histplot(train_df, x='SalePrice', kde=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:31.750854Z","iopub.execute_input":"2022-07-29T10:24:31.751186Z","iopub.status.idle":"2022-07-29T10:24:32.197021Z","shell.execute_reply.started":"2022-07-29T10:24:31.751156Z","shell.execute_reply":"2022-07-29T10:24:32.195617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.corr()['SalePrice'].sort_values(ascending=False)","metadata":{"scrolled":true,"tags":[],"execution":{"iopub.status.busy":"2022-07-29T10:24:32.198747Z","iopub.execute_input":"2022-07-29T10:24:32.199194Z","iopub.status.idle":"2022-07-29T10:24:32.430854Z","shell.execute_reply.started":"2022-07-29T10:24:32.199149Z","shell.execute_reply":"2022-07-29T10:24:32.429408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(20,20))\nplt.title('Correlation between columns')\nsns.heatmap(train_df.corr())","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:32.432505Z","iopub.execute_input":"2022-07-29T10:24:32.432998Z","iopub.status.idle":"2022-07-29T10:24:37.342249Z","shell.execute_reply.started":"2022-07-29T10:24:32.432953Z","shell.execute_reply":"2022-07-29T10:24:37.341038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Conclusion\n- SalePrice is high correlated to OverallQual, GrLivArea features","metadata":{}},{"cell_type":"code","source":"test_df['Heating'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:37.343563Z","iopub.execute_input":"2022-07-29T10:24:37.344003Z","iopub.status.idle":"2022-07-29T10:24:37.355312Z","shell.execute_reply.started":"2022-07-29T10:24:37.343948Z","shell.execute_reply":"2022-07-29T10:24:37.354046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = clean_data(test_df, test=True)\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:37.361453Z","iopub.execute_input":"2022-07-29T10:24:37.362248Z","iopub.status.idle":"2022-07-29T10:24:37.446474Z","shell.execute_reply.started":"2022-07-29T10:24:37.362199Z","shell.execute_reply":"2022-07-29T10:24:37.445588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols_to_del_4 = set(train_df.columns)\ncols_to_del_4 = cols_to_del_4.difference(test_df.columns)\ncols_to_del_4.remove('SalePrice')\ntrain_df.drop(columns=cols_to_del_4, inplace=True, axis=1)\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:37.447978Z","iopub.execute_input":"2022-07-29T10:24:37.448587Z","iopub.status.idle":"2022-07-29T10:24:37.480000Z","shell.execute_reply.started":"2022-07-29T10:24:37.448526Z","shell.execute_reply":"2022-07-29T10:24:37.478852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = train_df.drop(columns=['SalePrice'], axis=1)\nY = train_df['SalePrice']","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:37.481742Z","iopub.execute_input":"2022-07-29T10:24:37.482060Z","iopub.status.idle":"2022-07-29T10:24:37.488471Z","shell.execute_reply.started":"2022-07-29T10:24:37.482032Z","shell.execute_reply":"2022-07-29T10:24:37.487498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LinearRegression\nfrom sklearn.metrics import mean_squared_log_error\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.preprocessing import MinMaxScaler","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:37.489678Z","iopub.execute_input":"2022-07-29T10:24:37.490435Z","iopub.status.idle":"2022-07-29T10:24:37.498602Z","shell.execute_reply.started":"2022-07-29T10:24:37.490405Z","shell.execute_reply":"2022-07-29T10:24:37.497792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_val, Y_train, Y_val = train_test_split(X, Y, test_size=0.2, random_state=21)\nX_train.shape, X_val.shape, Y_train.shape, Y_val.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:37.500205Z","iopub.execute_input":"2022-07-29T10:24:37.500908Z","iopub.status.idle":"2022-07-29T10:24:37.520275Z","shell.execute_reply.started":"2022-07-29T10:24:37.500865Z","shell.execute_reply":"2022-07-29T10:24:37.519320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scores_array = []","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:37.521925Z","iopub.execute_input":"2022-07-29T10:24:37.522481Z","iopub.status.idle":"2022-07-29T10:24:37.526716Z","shell.execute_reply.started":"2022-07-29T10:24:37.522444Z","shell.execute_reply":"2022-07-29T10:24:37.525730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_lin_reg = make_pipeline(MinMaxScaler(), LinearRegression())\nmodel_lin_reg.fit(X_train, Y_train)\nY_train_pred = model_lin_reg.predict(X_train)\nY_val_pred = model_lin_reg.predict(X_val)\nscores_array.append(np.sqrt(mean_squared_log_error(Y_val, Y_val_pred)))\nprint(f\"RMSLE train: {np.sqrt(mean_squared_log_error(Y_train, Y_train_pred))}\")\nprint(f\"RMSLE test: {np.sqrt(mean_squared_log_error(Y_val, Y_val_pred))}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:37.527902Z","iopub.execute_input":"2022-07-29T10:24:37.528733Z","iopub.status.idle":"2022-07-29T10:24:37.719831Z","shell.execute_reply.started":"2022-07-29T10:24:37.528691Z","shell.execute_reply":"2022-07-29T10:24:37.717199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import ElasticNet","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:37.722165Z","iopub.execute_input":"2022-07-29T10:24:37.722928Z","iopub.status.idle":"2022-07-29T10:24:37.728689Z","shell.execute_reply.started":"2022-07-29T10:24:37.722881Z","shell.execute_reply":"2022-07-29T10:24:37.727445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_elastic = make_pipeline(MinMaxScaler(), ElasticNet())\nmodel_elastic.fit(X_train, Y_train)\nY_train_pred = model_elastic.predict(X_train)\nY_val_pred = model_elastic.predict(X_val)\nscores_array.append(np.sqrt(mean_squared_log_error(Y_val, Y_val_pred)))\nprint(f\"RMSLE train: {np.sqrt(mean_squared_log_error(Y_train, Y_train_pred))}\")\nprint(f\"RMSLE test: {np.sqrt(mean_squared_log_error(Y_val, Y_val_pred))}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:37.730900Z","iopub.execute_input":"2022-07-29T10:24:37.732619Z","iopub.status.idle":"2022-07-29T10:24:37.817432Z","shell.execute_reply.started":"2022-07-29T10:24:37.732572Z","shell.execute_reply":"2022-07-29T10:24:37.815042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.svm import SVR","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:37.827118Z","iopub.execute_input":"2022-07-29T10:24:37.831285Z","iopub.status.idle":"2022-07-29T10:24:37.844524Z","shell.execute_reply.started":"2022-07-29T10:24:37.831217Z","shell.execute_reply":"2022-07-29T10:24:37.842522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_svr = make_pipeline(MinMaxScaler(), SVR())\nmodel_svr.fit(X_train, Y_train)\nY_train_pred = model_svr.predict(X_train)\nY_val_pred = model_svr.predict(X_val)\nscores_array.append(np.sqrt(mean_squared_log_error(Y_val, Y_val_pred)))\nprint(f\"RMSLE train: {np.sqrt(mean_squared_log_error(Y_train, Y_train_pred))}\")\nprint(f\"RMSLE test: {np.sqrt(mean_squared_log_error(Y_val, Y_val_pred))}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:37.853611Z","iopub.execute_input":"2022-07-29T10:24:37.857889Z","iopub.status.idle":"2022-07-29T10:24:38.654348Z","shell.execute_reply.started":"2022-07-29T10:24:37.857831Z","shell.execute_reply":"2022-07-29T10:24:38.652625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestRegressor","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:38.658572Z","iopub.execute_input":"2022-07-29T10:24:38.658934Z","iopub.status.idle":"2022-07-29T10:24:38.740816Z","shell.execute_reply.started":"2022-07-29T10:24:38.658902Z","shell.execute_reply":"2022-07-29T10:24:38.739572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_rfr = make_pipeline(MinMaxScaler(), RandomForestRegressor(max_depth=5))\nmodel_rfr.fit(X_train, Y_train)\nY_train_pred = model_rfr.predict(X_train)\nY_val_pred = model_rfr.predict(X_val)\nscores_array.append(np.sqrt(mean_squared_log_error(Y_val, Y_val_pred)))\nprint(f\"RMSLE train: {np.sqrt(mean_squared_log_error(Y_train, Y_train_pred))}\")\nprint(f\"RMSLE test: {np.sqrt(mean_squared_log_error(Y_val, Y_val_pred))}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:38.742343Z","iopub.execute_input":"2022-07-29T10:24:38.743685Z","iopub.status.idle":"2022-07-29T10:24:39.727345Z","shell.execute_reply.started":"2022-07-29T10:24:38.743638Z","shell.execute_reply":"2022-07-29T10:24:39.726603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import GradientBoostingRegressor","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:39.728764Z","iopub.execute_input":"2022-07-29T10:24:39.729648Z","iopub.status.idle":"2022-07-29T10:24:39.733879Z","shell.execute_reply.started":"2022-07-29T10:24:39.729609Z","shell.execute_reply":"2022-07-29T10:24:39.732874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_gbr = make_pipeline(MinMaxScaler(), GradientBoostingRegressor(max_depth=5))\nmodel_gbr.fit(X_train, Y_train)\nY_train_pred = model_gbr.predict(X_train)\nY_val_pred = model_gbr.predict(X_val)\nscores_array.append(np.sqrt(mean_squared_log_error(Y_val, Y_val_pred)))\nprint(f\"RMSLE train: {np.sqrt(mean_squared_log_error(Y_train, Y_train_pred))}\")\nprint(f\"RMSLE test: {np.sqrt(mean_squared_log_error(Y_val, Y_val_pred))}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:39.735250Z","iopub.execute_input":"2022-07-29T10:24:39.735563Z","iopub.status.idle":"2022-07-29T10:24:40.816680Z","shell.execute_reply.started":"2022-07-29T10:24:39.735512Z","shell.execute_reply":"2022-07-29T10:24:40.815496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import AdaBoostRegressor","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:40.818246Z","iopub.execute_input":"2022-07-29T10:24:40.819337Z","iopub.status.idle":"2022-07-29T10:24:40.824481Z","shell.execute_reply.started":"2022-07-29T10:24:40.819296Z","shell.execute_reply":"2022-07-29T10:24:40.823174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_abr = make_pipeline(MinMaxScaler(), AdaBoostRegressor(n_estimators=100))\nmodel_abr.fit(X_train, Y_train)\nY_train_pred = model_abr.predict(X_train)\nY_val_pred = model_abr.predict(X_val)\nscores_array.append(np.sqrt(mean_squared_log_error(Y_val, Y_val_pred)))\nprint(f\"RMSLE train: {np.sqrt(mean_squared_log_error(Y_train, Y_train_pred))}\")\nprint(f\"RMSLE test: {np.sqrt(mean_squared_log_error(Y_val, Y_val_pred))}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:40.826114Z","iopub.execute_input":"2022-07-29T10:24:40.826474Z","iopub.status.idle":"2022-07-29T10:24:41.608124Z","shell.execute_reply.started":"2022-07-29T10:24:40.826443Z","shell.execute_reply":"2022-07-29T10:24:41.606975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import xgboost as xg","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:41.609394Z","iopub.execute_input":"2022-07-29T10:24:41.609741Z","iopub.status.idle":"2022-07-29T10:24:41.761088Z","shell.execute_reply.started":"2022-07-29T10:24:41.609711Z","shell.execute_reply":"2022-07-29T10:24:41.759970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_xg = make_pipeline(MinMaxScaler(), xg.XGBRFRegressor())\nmodel_xg.fit(X_train, Y_train)\nY_train_pred = model_xg.predict(X_train)\nY_val_pred = model_xg.predict(X_val)\nscores_array.append(np.sqrt(mean_squared_log_error(Y_val, Y_val_pred)))\nprint(f\"RMSLE train: {np.sqrt(mean_squared_log_error(Y_train, Y_train_pred))}\")\nprint(f\"RMSLE test: {np.sqrt(mean_squared_log_error(Y_val, Y_val_pred))}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:41.766263Z","iopub.execute_input":"2022-07-29T10:24:41.766645Z","iopub.status.idle":"2022-07-29T10:24:42.242201Z","shell.execute_reply.started":"2022-07-29T10:24:41.766603Z","shell.execute_reply":"2022-07-29T10:24:42.241274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scores = pd.Series(data=scores_array, index=['LinearRegression', 'ElasticNet', 'SVR', 'RandomForestRegressor', 'GradientBoostingRegressor', 'GradientBoostingRegressor', 'XGBRFRegressor'])\nscores.sort_values(ascending=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:42.246136Z","iopub.execute_input":"2022-07-29T10:24:42.248694Z","iopub.status.idle":"2022-07-29T10:24:42.260351Z","shell.execute_reply.started":"2022-07-29T10:24:42.248651Z","shell.execute_reply":"2022-07-29T10:24:42.259428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in test_df.columns:\n    if test_df[col].isna().sum() != 0:\n        print(col)","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:42.262396Z","iopub.execute_input":"2022-07-29T10:24:42.262929Z","iopub.status.idle":"2022-07-29T10:24:42.303378Z","shell.execute_reply.started":"2022-07-29T10:24:42.262887Z","shell.execute_reply":"2022-07-29T10:24:42.302190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res = model_gbr.predict(test_df)\nres","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:42.305161Z","iopub.execute_input":"2022-07-29T10:24:42.305650Z","iopub.status.idle":"2022-07-29T10:24:42.326933Z","shell.execute_reply.started":"2022-07-29T10:24:42.305592Z","shell.execute_reply":"2022-07-29T10:24:42.325491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_df = pd.DataFrame({'Id': range(1461, 2920), 'SalePrice': res})\nfinal_df.to_csv('submission.csv', sep=',', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-29T10:24:42.328435Z","iopub.execute_input":"2022-07-29T10:24:42.328829Z","iopub.status.idle":"2022-07-29T10:24:42.344949Z","shell.execute_reply.started":"2022-07-29T10:24:42.328795Z","shell.execute_reply":"2022-07-29T10:24:42.343602Z"},"trusted":true},"execution_count":null,"outputs":[]}]}