{"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":"!pip install --pre -q pycaret","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:24:43.393151Z","iopub.execute_input":"2022-08-06T10:24:43.393861Z","iopub.status.idle":"2022-08-06T10:25:36.264124Z","shell.execute_reply.started":"2022-08-06T10:24:43.393763Z","shell.execute_reply":"2022-08-06T10:25:36.262482Z"},"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\nfrom numba import njit\n\nfrom pycaret.regression import setup, compare_models\nimport catboost\n\npd.set_option('max_columns', 30)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-06T10:25:36.267247Z","iopub.execute_input":"2022-08-06T10:25:36.267627Z","iopub.status.idle":"2022-08-06T10:25:42.717544Z","shell.execute_reply.started":"2022-08-06T10:25:36.267589Z","shell.execute_reply":"2022-08-06T10:25:42.716274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('../input/house-prices-advanced-regression-techniques/train.csv', index_col='Id')\ntest = pd.read_csv('../input/house-prices-advanced-regression-techniques/test.csv', index_col='Id')","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:42.719383Z","iopub.execute_input":"2022-08-06T10:25:42.719887Z","iopub.status.idle":"2022-08-06T10:25:42.798271Z","shell.execute_reply.started":"2022-08-06T10:25:42.719832Z","shell.execute_reply":"2022-08-06T10:25:42.796997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"yy = np.log(pd.Series(train.SalePrice).reset_index(drop=True))","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:42.800826Z","iopub.execute_input":"2022-08-06T10:25:42.801272Z","iopub.status.idle":"2022-08-06T10:25:43.406155Z","shell.execute_reply.started":"2022-08-06T10:25:42.801234Z","shell.execute_reply":"2022-08-06T10:25:43.404912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def cleandata1(df1,df2):\n    return (pd.concat((df1, df2))\n            .reset_index()\n            .select_dtypes(['int64', 'float64'])\n            .drop('MoSold', axis=1)\n            .dropna(axis=1)\n            )","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:43.407620Z","iopub.execute_input":"2022-08-06T10:25:43.408112Z","iopub.status.idle":"2022-08-06T10:25:43.418501Z","shell.execute_reply.started":"2022-08-06T10:25:43.408064Z","shell.execute_reply":"2022-08-06T10:25:43.417506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cleandata1(train, test).head()","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:43.419921Z","iopub.execute_input":"2022-08-06T10:25:43.420281Z","iopub.status.idle":"2022-08-06T10:25:43.483422Z","shell.execute_reply.started":"2022-08-06T10:25:43.420249Z","shell.execute_reply":"2022-08-06T10:25:43.482197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def col(colm):\n    return cleandata1(train, test)[colm]","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:43.485187Z","iopub.execute_input":"2022-08-06T10:25:43.485918Z","iopub.status.idle":"2022-08-06T10:25:43.491718Z","shell.execute_reply.started":"2022-08-06T10:25:43.485871Z","shell.execute_reply":"2022-08-06T10:25:43.490256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cleandata1(train, test).columns","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:43.493446Z","iopub.execute_input":"2022-08-06T10:25:43.494105Z","iopub.status.idle":"2022-08-06T10:25:43.530511Z","shell.execute_reply.started":"2022-08-06T10:25:43.494065Z","shell.execute_reply":"2022-08-06T10:25:43.529673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(30, 20))\n(sns\n .heatmap(data=(pd\n                .concat([cleandata1(train, test)[:1460], yy], axis=1)\n                .corr()), annot=True)\n\n)","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:43.531883Z","iopub.execute_input":"2022-08-06T10:25:43.532502Z","iopub.status.idle":"2022-08-06T10:25:46.834642Z","shell.execute_reply.started":"2022-08-06T10:25:43.532465Z","shell.execute_reply":"2022-08-06T10:25:46.833471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def col2(colm):\n    return cleandata2()[colm]","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:46.838232Z","iopub.execute_input":"2022-08-06T10:25:46.839325Z","iopub.status.idle":"2022-08-06T10:25:46.844637Z","shell.execute_reply.started":"2022-08-06T10:25:46.839280Z","shell.execute_reply":"2022-08-06T10:25:46.843487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"no_na_meaning = ['SaleType', 'Functional', 'KitchenQual', 'Electrical', 'MasVnrType', 'Exterior1st', 'Exterior2nd', 'Utilities', 'MSZoning']","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:46.846256Z","iopub.execute_input":"2022-08-06T10:25:46.846610Z","iopub.status.idle":"2022-08-06T10:25:46.857482Z","shell.execute_reply.started":"2022-08-06T10:25:46.846578Z","shell.execute_reply":"2022-08-06T10:25:46.855783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def cleandata2():\n    return (pd.concat((train, test))\n            .reset_index()\n            .select_dtypes('object')\n            .dropna(axis=1)\n           ).reset_index(drop=True)\ncleandata2()","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:46.859887Z","iopub.execute_input":"2022-08-06T10:25:46.860443Z","iopub.status.idle":"2022-08-06T10:25:46.930669Z","shell.execute_reply.started":"2022-08-06T10:25:46.860390Z","shell.execute_reply":"2022-08-06T10:25:46.929247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.get_dummies(cleandata2()).head()","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:46.932406Z","iopub.execute_input":"2022-08-06T10:25:46.932881Z","iopub.status.idle":"2022-08-06T10:25:47.010554Z","shell.execute_reply.started":"2022-08-06T10:25:46.932834Z","shell.execute_reply":"2022-08-06T10:25:47.009433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.DataFrame({\n    'x0':np.ones(cleandata1(train, test).shape[0]),\n    'x1':np.square(col('OverallQual')),\n    'x2':np.sqrt(np.sqrt(np.log(col('OverallQual')))),\n#     'x3':col('YearBuilt'),\n    'x4':np.log(col('LotArea')),\n    'x5':np.exp(1/(np.cos((col('YearBuilt')/col('YearRemodAdd'))/(col('YearBuilt')/col('YrSold'))))),\n#     'x6':np.sin(col('YearRemodAdd')),\n    'x7':col('FullBath') + col('HalfBath'),\n    'x8':col('1stFlrSF') + col('2ndFlrSF'),\n    'x11':(col('BedroomAbvGr') * col('GrLivArea'))**0.25,\n    'x12':np.log1p(col('KitchenAbvGr') * col('GrLivArea'))**4,\n    'x13':col('TotRmsAbvGrd') - col('BedroomAbvGr') - col('KitchenAbvGr'),\n    'x14':col('Fireplaces') * col('WoodDeckSF'),\n    'x15':np.log(col('TotRmsAbvGrd')),\n#     'x16':col('Fireplaces')\n}).reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:47.011588Z","iopub.execute_input":"2022-08-06T10:25:47.011989Z","iopub.status.idle":"2022-08-06T10:25:47.510399Z","shell.execute_reply.started":"2022-08-06T10:25:47.011952Z","shell.execute_reply":"2022-08-06T10:25:47.509089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xx = pd.concat((df, np.square(cleandata1(train, test)), pd.get_dummies(cleandata2())), axis=1).reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:47.512029Z","iopub.execute_input":"2022-08-06T10:25:47.513344Z","iopub.status.idle":"2022-08-06T10:25:47.597734Z","shell.execute_reply.started":"2022-08-06T10:25:47.513304Z","shell.execute_reply":"2022-08-06T10:25:47.596261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# S = setup(pd.concat([xx[:1460], np.log(yy)], axis=1), target='SalePrice')","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:47.599462Z","iopub.execute_input":"2022-08-06T10:25:47.600191Z","iopub.status.idle":"2022-08-06T10:25:47.604656Z","shell.execute_reply.started":"2022-08-06T10:25:47.600142Z","shell.execute_reply":"2022-08-06T10:25:47.603414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"0.0120, 0.0135, 0.0124, 0.0121, 0.0114, 0.0109, 0.0108, 0.0106","metadata":{}},{"cell_type":"code","source":"# S.compare_models()","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:25:47.606354Z","iopub.execute_input":"2022-08-06T10:25:47.606937Z","iopub.status.idle":"2022-08-06T10:25:47.617238Z","shell.execute_reply.started":"2022-08-06T10:25:47.606902Z","shell.execute_reply":"2022-08-06T10:25:47.616191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model1 = catboost.CatBoostRegressor(iterations=10000)\nmodel1.fit(xx[:1460], np.log(yy), verbose=0)","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:52:10.556270Z","iopub.execute_input":"2022-08-06T10:52:10.556655Z","iopub.status.idle":"2022-08-06T10:52:45.323815Z","shell.execute_reply.started":"2022-08-06T10:52:10.556624Z","shell.execute_reply":"2022-08-06T10:52:45.322060Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction = model1.predict(xx)","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:49:44.893322Z","iopub.execute_input":"2022-08-06T10:49:44.894131Z","iopub.status.idle":"2022-08-06T10:49:44.926443Z","shell.execute_reply.started":"2022-08-06T10:49:44.894085Z","shell.execute_reply":"2022-08-06T10:49:44.925353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Prediction = np.exp(np.exp(prediction))\nPrediction","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:49:53.990826Z","iopub.execute_input":"2022-08-06T10:49:53.991226Z","iopub.status.idle":"2022-08-06T10:49:53.998662Z","shell.execute_reply.started":"2022-08-06T10:49:53.991193Z","shell.execute_reply":"2022-08-06T10:49:53.997524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# cleandata1(train, test).Id","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:26:23.355112Z","iopub.execute_input":"2022-08-06T10:26:23.356136Z","iopub.status.idle":"2022-08-06T10:26:23.366080Z","shell.execute_reply.started":"2022-08-06T10:26:23.356094Z","shell.execute_reply":"2022-08-06T10:26:23.364733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.concat((cleandata1(train, test).Id, pd.Series(Prediction, name='SalePrice')), axis=1)[1460:]\nsubmission","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:26:23.367502Z","iopub.execute_input":"2022-08-06T10:26:23.367963Z","iopub.status.idle":"2022-08-06T10:26:23.412251Z","shell.execute_reply.started":"2022-08-06T10:26:23.367919Z","shell.execute_reply":"2022-08-06T10:26:23.411203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('./submission_12.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-06T10:26:23.413486Z","iopub.execute_input":"2022-08-06T10:26:23.413823Z","iopub.status.idle":"2022-08-06T10:26:23.419115Z","shell.execute_reply.started":"2022-08-06T10:26:23.413792Z","shell.execute_reply":"2022-08-06T10:26:23.417732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}