{"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":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\ntrain_data = pd.read_csv(\"../input/house-prices-advanced-regression-techniques/train.csv\")\ntrain_data.head()","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-27T08:18:50.867949Z","iopub.execute_input":"2022-07-27T08:18:50.868425Z","iopub.status.idle":"2022-07-27T08:18:50.924297Z","shell.execute_reply.started":"2022-07-27T08:18:50.868388Z","shell.execute_reply":"2022-07-27T08:18:50.923185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data = pd.read_csv(\"../input/house-prices-advanced-regression-techniques/test.csv\")\ntest_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-27T08:18:51.219225Z","iopub.execute_input":"2022-07-27T08:18:51.220003Z","iopub.status.idle":"2022-07-27T08:18:51.273369Z","shell.execute_reply.started":"2022-07-27T08:18:51.219959Z","shell.execute_reply":"2022-07-27T08:18:51.272074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 删除过于少的列\n# train_data_ = train_data.dropna(axis = 1)\ntrain_data_ = train_data.drop(['LotFrontage', 'Alley', 'FireplaceQu', 'PoolQC', 'Fence', 'MiscFeature'], axis = 1)\ntrain_data_.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-27T08:18:51.511516Z","iopub.execute_input":"2022-07-27T08:18:51.511992Z","iopub.status.idle":"2022-07-27T08:18:51.542856Z","shell.execute_reply.started":"2022-07-27T08:18:51.511953Z","shell.execute_reply":"2022-07-27T08:18:51.541544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 解决缺失值\n# from sklearn.impute import KNNImputer\n# imputer = KNNImputer(n_neighbors = 5)\n# imputer.fit_transform(train_data_[['MasVnrType', 'MasVnrArea', 'BsmtQual', '']])\ntrain_data_ = train_data_.dropna(axis = 0)\ntrain_data_.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-27T08:18:51.780107Z","iopub.execute_input":"2022-07-27T08:18:51.781258Z","iopub.status.idle":"2022-07-27T08:18:51.819456Z","shell.execute_reply.started":"2022-07-27T08:18:51.781200Z","shell.execute_reply":"2022-07-27T08:18:51.818241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data_ = test_data.drop(['LotFrontage', 'Alley', 'FireplaceQu', 'PoolQC', 'Fence', 'MiscFeature'], axis = 1)\ntest_data_ = test_data_.dropna(axis = 0)\ntest_data_.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-27T08:18:51.904926Z","iopub.execute_input":"2022-07-27T08:18:51.905794Z","iopub.status.idle":"2022-07-27T08:18:51.945863Z","shell.execute_reply.started":"2022-07-27T08:18:51.905734Z","shell.execute_reply":"2022-07-27T08:18:51.944448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from collections import Counter\nresult = Counter(train_data_['SaleCondition'])\nprint(result)","metadata":{"execution":{"iopub.status.busy":"2022-07-27T08:30:13.590851Z","iopub.execute_input":"2022-07-27T08:30:13.591376Z","iopub.status.idle":"2022-07-27T08:30:13.598359Z","shell.execute_reply.started":"2022-07-27T08:30:13.591330Z","shell.execute_reply":"2022-07-27T08:30:13.597186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\ny = train_data_['SalePrice']\nX = pd.get_dummies(train_data_.drop('SalePrice', axis = 1))\nX_test = pd.get_dummies(test_data_)\n\nX.info()\nX_test.info()\n# model = RandomForestClassifier(n_estimators=200, max_depth=5, random_state=1)\n# model.fit(X, y)\n# predictions = model.predict(X_test)\n\n# output = pd.DataFrame({'Id': test_data.Id, 'SalePrice': predictions})\n# output.to_csv('submission.csv', index=False)\n# print(\"Your submission was successfully saved!\")","metadata":{"execution":{"iopub.status.busy":"2022-07-27T08:39:52.977196Z","iopub.execute_input":"2022-07-27T08:39:52.977650Z","iopub.status.idle":"2022-07-27T08:39:53.096462Z","shell.execute_reply.started":"2022-07-27T08:39:52.977616Z","shell.execute_reply":"2022-07-27T08:39:53.095139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}