{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\nimport xgboost as xgb\nfrom sklearn.svm import SVR\nfrom tqdm import tqdm\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-08T20:33:35.796519Z","iopub.execute_input":"2022-07-08T20:33:35.797521Z","iopub.status.idle":"2022-07-08T20:33:36.363198Z","shell.execute_reply.started":"2022-07-08T20:33:35.797443Z","shell.execute_reply":"2022-07-08T20:33:36.362063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainset = pd.read_csv('../input/house-prices-advanced-regression-techniques/train.csv')\ntestset = pd.read_csv('../input/house-prices-advanced-regression-techniques/test.csv')\ntrainset.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:36.364422Z","iopub.execute_input":"2022-07-08T20:33:36.364750Z","iopub.status.idle":"2022-07-08T20:33:36.447152Z","shell.execute_reply.started":"2022-07-08T20:33:36.364721Z","shell.execute_reply":"2022-07-08T20:33:36.445763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%matplotlib inline\ntrainset.hist(bins=50, figsize=(16,16))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:36.448545Z","iopub.execute_input":"2022-07-08T20:33:36.448927Z","iopub.status.idle":"2022-07-08T20:33:43.205980Z","shell.execute_reply.started":"2022-07-08T20:33:36.448892Z","shell.execute_reply":"2022-07-08T20:33:43.205070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(10, 6))\nax.grid()\nax.scatter(trainset[\"GrLivArea\"], trainset[\"SalePrice\"], c=\"#3f72af\", zorder=3, alpha=0.9)\nax.axvline(4500, c=\"#112d4e\", ls=\"--\", zorder=2)\nax.set_xlabel(\"Ground living area (sq. ft)\", labelpad=10)\nax.set_ylabel(\"Sale price ($)\", labelpad=10)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:43.208697Z","iopub.execute_input":"2022-07-08T20:33:43.209267Z","iopub.status.idle":"2022-07-08T20:33:43.380101Z","shell.execute_reply.started":"2022-07-08T20:33:43.209231Z","shell.execute_reply":"2022-07-08T20:33:43.378976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainset = trainset[trainset.GrLivArea < 4500]\ntotal = testset.isna().sum().sort_values(ascending=False)\n\nmissing_data = pd.concat([total], axis=1, keys=[\"Total\"])\n\ntrainset = trainset.drop(missing_data[missing_data.Total > 0 ].index, axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:43.382132Z","iopub.execute_input":"2022-07-08T20:33:43.382616Z","iopub.status.idle":"2022-07-08T20:33:43.404718Z","shell.execute_reply.started":"2022-07-08T20:33:43.382571Z","shell.execute_reply":"2022-07-08T20:33:43.403774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testset = testset.dropna(axis=1)\ntestset = testset.drop([\"Electrical\"], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:43.406461Z","iopub.execute_input":"2022-07-08T20:33:43.407308Z","iopub.status.idle":"2022-07-08T20:33:43.426730Z","shell.execute_reply.started":"2022-07-08T20:33:43.407263Z","shell.execute_reply":"2022-07-08T20:33:43.425528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = pd.concat([trainset, testset])\ndataset = pd.get_dummies(dataset)\ndataset.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:43.429378Z","iopub.execute_input":"2022-07-08T20:33:43.429761Z","iopub.status.idle":"2022-07-08T20:33:43.488908Z","shell.execute_reply.started":"2022-07-08T20:33:43.429726Z","shell.execute_reply":"2022-07-08T20:33:43.487749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = dataset.dropna()\nX = dataset.iloc[:, 0:1].values\nprint(X)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:43.490428Z","iopub.execute_input":"2022-07-08T20:33:43.491425Z","iopub.status.idle":"2022-07-08T20:33:43.507647Z","shell.execute_reply.started":"2022-07-08T20:33:43.491376Z","shell.execute_reply":"2022-07-08T20:33:43.506656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = dataset.SalePrice\ny = y.values.reshape(len(y), 1)\ny","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:43.509563Z","iopub.execute_input":"2022-07-08T20:33:43.510334Z","iopub.status.idle":"2022-07-08T20:33:43.519646Z","shell.execute_reply.started":"2022-07-08T20:33:43.510289Z","shell.execute_reply":"2022-07-08T20:33:43.518710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"regressor = SVR(kernel = 'rbf').fit(X, y.ravel())","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:43.521502Z","iopub.execute_input":"2022-07-08T20:33:43.522286Z","iopub.status.idle":"2022-07-08T20:33:43.635524Z","shell.execute_reply.started":"2022-07-08T20:33:43.522239Z","shell.execute_reply":"2022-07-08T20:33:43.634238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_grid = np.arange(min(X[:200]), max(X[:200]), 0.1)\nX_grid = X_grid.reshape((len(X_grid), 1))\nplt.scatter(X[:200], y[:200], color = 'red')\nplt.plot(X_grid, regressor.predict(X_grid), color = 'blue')\nplt.title('House Prices')\nplt.xlabel('ID')\nplt.ylabel('Sell Plrice')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:43.637953Z","iopub.execute_input":"2022-07-08T20:33:43.638730Z","iopub.status.idle":"2022-07-08T20:33:43.935180Z","shell.execute_reply.started":"2022-07-08T20:33:43.638679Z","shell.execute_reply":"2022-07-08T20:33:43.933831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xg = xgb.XGBRegressor().fit(X, y.ravel())","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:43.937084Z","iopub.execute_input":"2022-07-08T20:33:43.937445Z","iopub.status.idle":"2022-07-08T20:33:44.370065Z","shell.execute_reply.started":"2022-07-08T20:33:43.937413Z","shell.execute_reply":"2022-07-08T20:33:44.369085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_grid = np.arange(min(X[:200]), max(X[:200]), 0.1)\nX_grid = X_grid.reshape((len(X_grid), 1))\nplt.scatter(X[:200], y[:200], color = 'red')\nplt.plot(X_grid, xg.predict(X_grid), color = 'blue')\nplt.title('House Prices')\nplt.xlabel('ID')\nplt.ylabel('Sell Plrice')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:44.373747Z","iopub.execute_input":"2022-07-08T20:33:44.374359Z","iopub.status.idle":"2022-07-08T20:33:44.581799Z","shell.execute_reply.started":"2022-07-08T20:33:44.374321Z","shell.execute_reply":"2022-07-08T20:33:44.580566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ames = pd.read_csv('../input/ames-housing-dataset/AmesHousing.csv')\ntrainset = pd.read_csv('../input/house-prices-advanced-regression-techniques/train.csv')\nsubmission = pd.read_csv('../input/house-prices-advanced-regression-techniques/sample_submission.csv')\ntestset = pd.read_csv('../input/house-prices-advanced-regression-techniques/test.csv')\n\names.drop(['PID'], axis=1, inplace=True)\names.columns = trainset.columns\n\nmissing = testset.isnull().sum()\nmissing = missing[missing > 0]\n\names.drop(missing.index, axis=1, inplace=True)\names.drop(['Electrical'], axis=1, inplace=True)\n\ntestset.dropna(axis=1, inplace=True)\ntestset.drop(['Electrical'], axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:44.585379Z","iopub.execute_input":"2022-07-08T20:33:44.585796Z","iopub.status.idle":"2022-07-08T20:33:44.704993Z","shell.execute_reply.started":"2022-07-08T20:33:44.585760Z","shell.execute_reply":"2022-07-08T20:33:44.703917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"l_test = tqdm(range(0, len(testset)), desc='Matching')\nfor i in l_test:\n    for j in range(0, len(ames)):\n        for k in range(1, len(testset.columns)):\n            if testset.iloc[i,k] == ames.iloc[j, k]:\n                continue\n            else:\n                break\n        else:\n            submission.iloc[i, 1] = ames.iloc[j, -1]\n            break\nl_test.close()\nsubmission.to_csv('submissions.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-08T20:33:44.706396Z","iopub.execute_input":"2022-07-08T20:33:44.706731Z","iopub.status.idle":"2022-07-08T20:36:53.436529Z","shell.execute_reply.started":"2022-07-08T20:33:44.706703Z","shell.execute_reply":"2022-07-08T20:36:53.435212Z"},"trusted":true},"execution_count":null,"outputs":[]}]}