{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":9994,"databundleVersionId":752467,"sourceType":"competition"},{"sourceId":10807989,"sourceType":"datasetVersion","datasetId":6708953}],"dockerImageVersionId":30886,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# **Checkpoint 1**\n\nGroup Name: **Eagle_USU**","metadata":{}},{"cell_type":"markdown","source":"For checkpoint I, you will need to download the data and run some initial pre-processing on it. You should also make at least one dummy submission (all-positive, all-negative, most-frequency) on Kaggle and submit the score screenshot on Canvas.\n\n","metadata":{}},{"cell_type":"markdown","source":"## Loading the dataset","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\n\n\npath_data = \"/kaggle/input/ashrae-dataset/\"\n\ntrain_data = pd.read_csv(path_data + 'train.csv')\ntest_data = pd.read_csv(path_data + 'test.csv')\nbuilding_metadata = pd.read_csv(path_data + 'building_metadata.csv')\nweather_train = pd.read_csv(path_data + 'weather_train.csv')\nweather_test = pd.read_csv(path_data + 'weather_test.csv')\nsample_submission = pd.read_csv(path_data + 'sample_submission.csv')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-02-20T21:23:18.448757Z","iopub.execute_input":"2025-02-20T21:23:18.449111Z","iopub.status.idle":"2025-02-20T21:23:51.277185Z","shell.execute_reply.started":"2025-02-20T21:23:18.449084Z","shell.execute_reply":"2025-02-20T21:23:51.275865Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Showing the dataset","metadata":{}},{"cell_type":"code","source":"display(train_data.head())\ndisplay(test_data.head())\ndisplay(sample_submission)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-20T21:23:51.278626Z","iopub.execute_input":"2025-02-20T21:23:51.279049Z","iopub.status.idle":"2025-02-20T21:23:51.306592Z","shell.execute_reply.started":"2025-02-20T21:23:51.279006Z","shell.execute_reply":"2025-02-20T21:23:51.305464Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"display(building_metadata.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-20T21:23:51.308639Z","iopub.execute_input":"2025-02-20T21:23:51.309079Z","iopub.status.idle":"2025-02-20T21:23:51.324506Z","shell.execute_reply.started":"2025-02-20T21:23:51.309036Z","shell.execute_reply":"2025-02-20T21:23:51.323435Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"display(weather_train.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-20T21:23:51.325939Z","iopub.execute_input":"2025-02-20T21:23:51.326241Z","iopub.status.idle":"2025-02-20T21:23:51.354353Z","shell.execute_reply.started":"2025-02-20T21:23:51.326214Z","shell.execute_reply":"2025-02-20T21:23:51.352645Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"display(weather_test.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-20T21:23:51.356043Z","iopub.execute_input":"2025-02-20T21:23:51.356709Z","iopub.status.idle":"2025-02-20T21:23:51.386582Z","shell.execute_reply.started":"2025-02-20T21:23:51.356653Z","shell.execute_reply":"2025-02-20T21:23:51.385168Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"display(sample_submission.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-20T21:23:51.387924Z","iopub.execute_input":"2025-02-20T21:23:51.388336Z","iopub.status.idle":"2025-02-20T21:23:51.407155Z","shell.execute_reply.started":"2025-02-20T21:23:51.388295Z","shell.execute_reply":"2025-02-20T21:23:51.405866Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Merging the data","metadata":{}},{"cell_type":"code","source":"def prepare_data(X, building_data, weather_data, test=False):\n    \"\"\"\n    Preparing final dataset with all features.\n    \"\"\"\n    \n    X = X.merge(building_data, on=\"building_id\", how=\"left\")\n    X = X.merge(weather_data, on=[\"site_id\", \"timestamp\"], how=\"left\")\n    \n    X.timestamp = pd.to_datetime(X.timestamp, format=\"%Y-%m-%d %H:%M:%S\")\n    X.square_feet = np.log1p(X.square_feet)\n    \n    if not test:\n        X.sort_values(\"timestamp\", inplace=True)\n        X.reset_index(drop=True, inplace=True)\n        \n    holidays = [\"2016-01-01\", \"2016-01-18\", \"2016-02-15\", \"2016-05-30\", \"2016-07-04\",\n                \"2016-09-05\", \"2016-10-10\", \"2016-11-11\", \"2016-11-24\", \"2016-12-26\",\n                \"2017-01-01\", \"2017-01-16\", \"2017-02-20\", \"2017-05-29\", \"2017-07-04\",\n                \"2017-09-04\", \"2017-10-09\", \"2017-11-10\", \"2017-11-23\", \"2017-12-25\",\n                \"2018-01-01\", \"2018-01-15\", \"2018-02-19\", \"2018-05-28\", \"2018-07-04\",\n                \"2018-09-03\", \"2018-10-08\", \"2018-11-12\", \"2018-11-22\", \"2018-12-25\",\n                \"2019-01-01\"]\n    \n    X[\"hour\"] = X.timestamp.dt.hour\n    X[\"weekday\"] = X.timestamp.dt.weekday\n    X[\"is_holiday\"] = (X.timestamp.dt.date.astype(\"str\").isin(holidays)).astype(int)\n    \n    drop_features = [\"timestamp\", \"sea_level_pressure\", \"wind_direction\", \"wind_speed\"]\n\n    X.drop(drop_features, axis=1, inplace=True)\n\n    if test:\n        row_ids = X.row_id\n        X.drop(\"row_id\", axis=1, inplace=True)\n        return X, row_ids\n    else:\n        y = np.log1p(X.meter_reading)\n        X.drop(\"meter_reading\", axis=1, inplace=True)\n        return X, y","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-20T21:23:51.408196Z","iopub.execute_input":"2025-02-20T21:23:51.408549Z","iopub.status.idle":"2025-02-20T21:23:51.419165Z","shell.execute_reply.started":"2025-02-20T21:23:51.408518Z","shell.execute_reply":"2025-02-20T21:23:51.418005Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_full, y_train_full = prepare_data(train_data, building_metadata, weather_train)\n\ndisplay(y_train_full)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-20T21:23:51.421417Z","iopub.execute_input":"2025-02-20T21:23:51.421748Z","iopub.status.idle":"2025-02-20T21:24:39.858504Z","shell.execute_reply.started":"2025-02-20T21:23:51.421717Z","shell.execute_reply":"2025-02-20T21:24:39.857161Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_full, row_ids = prepare_data(test_data, building_metadata, weather_test, test=True)\n\ndisplay(test_full)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-20T21:24:39.860002Z","iopub.execute_input":"2025-02-20T21:24:39.860424Z","iopub.status.idle":"2025-02-20T21:25:58.113626Z","shell.execute_reply.started":"2025-02-20T21:24:39.860364Z","shell.execute_reply":"2025-02-20T21:25:58.112522Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Correlation Analysis","metadata":{}},{"cell_type":"code","source":"\n\n\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\n# Encode the categorical column 'primary_use'\ntrain_full['primary_use'] = train_full['primary_use'].astype('category').cat.codes\n\n# Calculate the correlation matrix\ncorr_matrix = train_full.corr()\n\n# Plot the heatmap\nplt.figure(figsize=(12, 8))\nsns.heatmap(corr_matrix, annot=True, cmap='coolwarm', fmt='.1f')\nplt.title('Correlation Heatmap')\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-20T21:25:58.114625Z","iopub.execute_input":"2025-02-20T21:25:58.114903Z","iopub.status.idle":"2025-02-20T21:26:13.272825Z","shell.execute_reply.started":"2025-02-20T21:25:58.114878Z","shell.execute_reply":"2025-02-20T21:26:13.271639Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Removing Nan values","metadata":{}},{"cell_type":"code","source":"train_data = train_data.dropna()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-20T21:26:13.274039Z","iopub.execute_input":"2025-02-20T21:26:13.274574Z","iopub.status.idle":"2025-02-20T21:26:14.753979Z","shell.execute_reply.started":"2025-02-20T21:26:13.274540Z","shell.execute_reply":"2025-02-20T21:26:14.752802Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Dummy Regression","metadata":{}},{"cell_type":"code","source":"mean_meter_reading = y_train_full.mean()\nprint(mean_meter_reading)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-20T21:26:14.755014Z","iopub.execute_input":"2025-02-20T21:26:14.755339Z","iopub.status.idle":"2025-02-20T21:26:14.851044Z","shell.execute_reply.started":"2025-02-20T21:26:14.755309Z","shell.execute_reply":"2025-02-20T21:26:14.849767Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"num_rows = len(test_full)  # Get the number of rows in test_full\nmean_meter_reading = y_train_full.mean()  # Compute the mean meter reading\n\n# Create the submission DataFrame\nsubmission_df = pd.DataFrame({\n    \"row_id\": range(num_rows),  # Sequential row IDs\n    \"meter_reading\": mean_meter_reading  # Fill with mean meter reading\n})\n\n# Save to CSV file\nsubmission_df.to_csv(\"submission.csv\", index=False)\n\nprint(\"CSV file 'submission.csv' created successfully!\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-20T21:26:14.852357Z","iopub.execute_input":"2025-02-20T21:26:14.852829Z","iopub.status.idle":"2025-02-20T21:27:31.130359Z","shell.execute_reply.started":"2025-02-20T21:26:14.852787Z","shell.execute_reply":"2025-02-20T21:27:31.129000Z"}},"outputs":[],"execution_count":null}]}