{"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\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport pickle\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-24T16:32:09.003395Z","iopub.execute_input":"2022-07-24T16:32:09.004245Z","iopub.status.idle":"2022-07-24T16:32:09.044396Z","shell.execute_reply.started":"2022-07-24T16:32:09.004147Z","shell.execute_reply":"2022-07-24T16:32:09.043178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"TrainData = pd.read_pickle(\"../input/housepricepredictionpreprocess1/Train_Data.pkl\")\nTestData = pd.read_pickle(\"../input/housepricepredictionpreprocess1/Test_Data.pkl\")\nLabels = pd.read_pickle(\"../input/housepricepredictionpreprocess1/Labels.pkl\")","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:32:09.046768Z","iopub.execute_input":"2022-07-24T16:32:09.047640Z","iopub.status.idle":"2022-07-24T16:32:09.090339Z","shell.execute_reply.started":"2022-07-24T16:32:09.047595Z","shell.execute_reply":"2022-07-24T16:32:09.089210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def IsNAN(x):\n    return np.array([isinstance(entry,float) and np.isnan(entry) for entry in x])","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:32:09.091825Z","iopub.execute_input":"2022-07-24T16:32:09.092470Z","iopub.status.idle":"2022-07-24T16:32:09.097054Z","shell.execute_reply.started":"2022-07-24T16:32:09.092425Z","shell.execute_reply":"2022-07-24T16:32:09.096241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(np.sum(IsNAN((TrainData.values).flatten())))","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:32:09.099170Z","iopub.execute_input":"2022-07-24T16:32:09.099782Z","iopub.status.idle":"2022-07-24T16:32:09.156947Z","shell.execute_reply.started":"2022-07-24T16:32:09.099742Z","shell.execute_reply":"2022-07-24T16:32:09.155355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import OrdinalEncoder\n\ndef encode(train, test):\n    enc = OrdinalEncoder()\n    train = enc.fit_transform(train.astype(str))\n    test = enc.fit_transform(test.astype(str))\n    return train, test","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:32:09.191630Z","iopub.execute_input":"2022-07-24T16:32:09.192081Z","iopub.status.idle":"2022-07-24T16:32:10.199188Z","shell.execute_reply.started":"2022-07-24T16:32:09.192046Z","shell.execute_reply":"2022-07-24T16:32:10.198200Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\ndef scale(train, test):\n    scaler = StandardScaler()\n    train = scaler.fit_transform(train)\n    test = scaler.transform(test)\n    return train,test","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:32:10.201765Z","iopub.execute_input":"2022-07-24T16:32:10.202454Z","iopub.status.idle":"2022-07-24T16:32:10.207828Z","shell.execute_reply.started":"2022-07-24T16:32:10.202405Z","shell.execute_reply":"2022-07-24T16:32:10.207006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = TrainData.copy()\ntest = TestData.copy()\ntrain,test = encode(train,test)\ntrain,test = scale(train,test)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:32:10.208974Z","iopub.execute_input":"2022-07-24T16:32:10.209880Z","iopub.status.idle":"2022-07-24T16:32:10.524879Z","shell.execute_reply.started":"2022-07-24T16:32:10.209844Z","shell.execute_reply":"2022-07-24T16:32:10.523685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(TrainData.shape)\nprint(train.shape)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:32:10.526128Z","iopub.execute_input":"2022-07-24T16:32:10.526429Z","iopub.status.idle":"2022-07-24T16:32:10.534439Z","shell.execute_reply.started":"2022-07-24T16:32:10.526402Z","shell.execute_reply":"2022-07-24T16:32:10.532936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(np.sum(np.isnan(test).flatten()))","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:32:10.538063Z","iopub.execute_input":"2022-07-24T16:32:10.538910Z","iopub.status.idle":"2022-07-24T16:32:10.546738Z","shell.execute_reply.started":"2022-07-24T16:32:10.538863Z","shell.execute_reply":"2022-07-24T16:32:10.545494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train, X_val, y_train, y_val = train_test_split(train, Labels, test_size=0.3, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:32:10.548563Z","iopub.execute_input":"2022-07-24T16:32:10.548874Z","iopub.status.idle":"2022-07-24T16:32:10.610045Z","shell.execute_reply.started":"2022-07-24T16:32:10.548848Z","shell.execute_reply":"2022-07-24T16:32:10.609171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LinearRegression\nreg = LinearRegression().fit(X_train, y_train)\nreg.score(X_val, y_val)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:32:10.612297Z","iopub.execute_input":"2022-07-24T16:32:10.612715Z","iopub.status.idle":"2022-07-24T16:32:10.723345Z","shell.execute_reply.started":"2022-07-24T16:32:10.612672Z","shell.execute_reply":"2022-07-24T16:32:10.722189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submissions = pd.read_csv(\"../input/house-prices-advanced-regression-techniques/sample_submission.csv\");\nsubmissions[\"SalePrice\"] = reg.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:34:47.733321Z","iopub.execute_input":"2022-07-24T16:34:47.733716Z","iopub.status.idle":"2022-07-24T16:34:47.749730Z","shell.execute_reply.started":"2022-07-24T16:34:47.733682Z","shell.execute_reply":"2022-07-24T16:34:47.747960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submissions.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:34:50.599407Z","iopub.execute_input":"2022-07-24T16:34:50.599799Z","iopub.status.idle":"2022-07-24T16:34:50.607273Z","shell.execute_reply.started":"2022-07-24T16:34:50.599768Z","shell.execute_reply":"2022-07-24T16:34:50.605846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submissions","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:34:56.446562Z","iopub.execute_input":"2022-07-24T16:34:56.447516Z","iopub.status.idle":"2022-07-24T16:34:56.460327Z","shell.execute_reply.started":"2022-07-24T16:34:56.447478Z","shell.execute_reply":"2022-07-24T16:34:56.459317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submissions.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:32:10.759552Z","iopub.execute_input":"2022-07-24T16:32:10.760717Z","iopub.status.idle":"2022-07-24T16:32:10.790415Z","shell.execute_reply.started":"2022-07-24T16:32:10.760667Z","shell.execute_reply":"2022-07-24T16:32:10.788986Z"},"trusted":true},"execution_count":null,"outputs":[]}]}