{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":96164,"databundleVersionId":11418275,"sourceType":"competition"}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"\n<h1 style=\"text-align:center; color:blue; font-size:60px\">W E L C O M E</h1>\n\n> <h4 style=\"text-align: justify\">\nNote: You will face some basic code to help other beginners like me. Please accept this logic before continuing.\n</h4>\n\n> <h4 style=\"text-align: justify\">\nSecond Note: This is a very inclusive notebook to understand these competition metrics and the logic behind them. If you want to join this competition and feel hesitant, you can determine what is it and what is not.\n</h4>\n\n<br>\n\n","metadata":{}},{"cell_type":"markdown","source":"<h2 style=\"text-align:center; color:pink\">Quick Questions</h2>\n\n###  Is there any NaN value?\n> Actually not but there are some missing minutes (about 1428 minutes). <br>\n[Is there a time skip?](#Is-there-a-time-skip?)\n\n###  Why there is a \"-\" prediction in submission data?\n> <p style=\"text-align:justify\"> Because in this competition we are responsible for guessing these values based on the other columns. So if there are \"+\" or \"-\" values as you can see, it means the time at the moment is more or less market price movement than the last time.</p>","metadata":{}},{"cell_type":"markdown","source":"<h2 style=\"text-align:center; color:pink\">Basic libraries</h2>","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport warnings\nwarnings.filterwarnings('ignore')\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:26:48.609163Z","iopub.execute_input":"2025-06-19T11:26:48.609443Z","iopub.status.idle":"2025-06-19T11:26:50.957689Z","shell.execute_reply.started":"2025-06-19T11:26:48.609422Z","shell.execute_reply":"2025-06-19T11:26:50.956409Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h2 style=\"text-align:center; color:pink\">Control</h2>","metadata":{}},{"cell_type":"code","source":"sub = pd.read_csv(\"/kaggle/input/drw-crypto-market-prediction/sample_submission.csv\")\nsub","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:26:50.959702Z","iopub.execute_input":"2025-06-19T11:26:50.960301Z","iopub.status.idle":"2025-06-19T11:26:51.428542Z","shell.execute_reply.started":"2025-06-19T11:26:50.960262Z","shell.execute_reply":"2025-06-19T11:26:51.427423Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h2 style=\"text-align:center; color:pink\">Train & Test Sets</h2>\n\n### What do they look like?","metadata":{}},{"cell_type":"code","source":"train = pd.read_parquet(\"/kaggle/input/drw-crypto-market-prediction/train.parquet\")\ntrain","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:26:51.429761Z","iopub.execute_input":"2025-06-19T11:26:51.430136Z","iopub.status.idle":"2025-06-19T11:27:18.702575Z","shell.execute_reply.started":"2025-06-19T11:26:51.430093Z","shell.execute_reply":"2025-06-19T11:27:18.700791Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test = pd.read_parquet(\"/kaggle/input/drw-crypto-market-prediction/test.parquet\")\ntest","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:27:18.705567Z","iopub.execute_input":"2025-06-19T11:27:18.705873Z","iopub.status.idle":"2025-06-19T11:27:50.730520Z","shell.execute_reply.started":"2025-06-19T11:27:18.705848Z","shell.execute_reply":"2025-06-19T11:27:50.729064Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### What are their shape?","metadata":{}},{"cell_type":"code","source":"print(\"TRAIN shape:\",train.shape)\nprint(\"TEST shape:\",test.shape)\nprint(\"-------------------------\")\nprint(\"Both have the same column length.\")\nprint(\"*Differences in the number of rows are:\",test.shape[0] - train.shape[0])\nprint(\"The test set has more row values.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:27:50.732312Z","iopub.execute_input":"2025-06-19T11:27:50.733203Z","iopub.status.idle":"2025-06-19T11:27:50.742420Z","shell.execute_reply.started":"2025-06-19T11:27:50.733094Z","shell.execute_reply":"2025-06-19T11:27:50.741175Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### What are the types of columns?","metadata":{}},{"cell_type":"code","source":"print(\"TRAIN \\n\",train.dtypes.value_counts(), \"\\n\")\nprint(\"TEST \\n\",test.dtypes.value_counts())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:27:50.743551Z","iopub.execute_input":"2025-06-19T11:27:50.743892Z","iopub.status.idle":"2025-06-19T11:27:50.783424Z","shell.execute_reply.started":"2025-06-19T11:27:50.743863Z","shell.execute_reply":"2025-06-19T11:27:50.782216Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h5 style=\"text-align:center; color:yellow\">All columns are float64 in both sets.</h5>","metadata":{"jp-MarkdownHeadingCollapsed":true}},{"cell_type":"markdown","source":"### Is there any Null or NaN value?","metadata":{}},{"cell_type":"code","source":"print(\"TRAIN SET:\",train.isnull().sum().value_counts())\nprint(\"TEST SET:\",test.isnull().sum().value_counts())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:27:50.784656Z","iopub.execute_input":"2025-06-19T11:27:50.784913Z","iopub.status.idle":"2025-06-19T11:27:57.973592Z","shell.execute_reply.started":"2025-06-19T11:27:50.784892Z","shell.execute_reply":"2025-06-19T11:27:57.972632Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h5 style=\"text-align:center; color:yellow\">The answer is: NO</h5>","metadata":{"jp-MarkdownHeadingCollapsed":true}},{"cell_type":"markdown","source":"### Let's check the Datetimes","metadata":{}},{"cell_type":"code","source":"train.index","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:27:57.974581Z","iopub.execute_input":"2025-06-19T11:27:57.974840Z","iopub.status.idle":"2025-06-19T11:27:58.000878Z","shell.execute_reply.started":"2025-06-19T11:27:57.974818Z","shell.execute_reply":"2025-06-19T11:27:57.999901Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.index","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:27:58.003177Z","iopub.execute_input":"2025-06-19T11:27:58.003566Z","iopub.status.idle":"2025-06-19T11:27:58.012570Z","shell.execute_reply.started":"2025-06-19T11:27:58.003541Z","shell.execute_reply":"2025-06-19T11:27:58.011136Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Is the training dataset in the proper order?","metadata":{}},{"cell_type":"code","source":"train.index.duplicated().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:27:58.016414Z","iopub.execute_input":"2025-06-19T11:27:58.016706Z","iopub.status.idle":"2025-06-19T11:27:58.102881Z","shell.execute_reply.started":"2025-06-19T11:27:58.016684Z","shell.execute_reply":"2025-06-19T11:27:58.101630Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Is the training dataset in the proper order?\nprint((train.index.to_series().diff().dt.total_seconds() < 0).sum())\n\n# The test set is hidden, so we don't need to control it.","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:27:58.104136Z","iopub.execute_input":"2025-06-19T11:27:58.104395Z","iopub.status.idle":"2025-06-19T11:27:58.147014Z","shell.execute_reply.started":"2025-06-19T11:27:58.104375Z","shell.execute_reply":"2025-06-19T11:27:58.146113Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h2 style=\"text-align:center; color:pink\">Is there a time skip?</h2>","metadata":{}},{"cell_type":"code","source":"test.index.diff().value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:27:58.148227Z","iopub.execute_input":"2025-06-19T11:27:58.148519Z","iopub.status.idle":"2025-06-19T11:27:58.177577Z","shell.execute_reply.started":"2025-06-19T11:27:58.148498Z","shell.execute_reply":"2025-06-19T11:27:58.176455Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h5 style=\"text-align:center; color:yellow\">The test set is very clear.</h5>","metadata":{}},{"cell_type":"code","source":"train.index.diff().value_counts().sort_index()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:27:58.178666Z","iopub.execute_input":"2025-06-19T11:27:58.178970Z","iopub.status.idle":"2025-06-19T11:27:58.216984Z","shell.execute_reply.started":"2025-06-19T11:27:58.178946Z","shell.execute_reply":"2025-06-19T11:27:58.216022Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"total = 0\n\n# How many time gaps totally we have?\ndef my_function(minute):\n    global total\n    summary = sum(train.index.diff() == pd.Timedelta(f\"{minute}min\"))\n    total += summary * minute\n    return total\n\nfor i in range(0,36):\n    if i == 1:\n        continue\n    else:\n        my_function(i)\n\nprint(f\"We have '{total}' missing lines & minutes in total.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:27:58.218122Z","iopub.execute_input":"2025-06-19T11:27:58.218577Z","iopub.status.idle":"2025-06-19T11:28:00.799909Z","shell.execute_reply.started":"2025-06-19T11:27:58.218542Z","shell.execute_reply":"2025-06-19T11:28:00.798538Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h5 style=\"text-align:center; color:yellow\">What it means? = There is a time gap. For example, we have a 35-minute gap between two lines. We will have to fix this.</h5>\n\n<br>\n\n<h5 style=\"text-align:center; color:yellow\">And we learned that we have only 1426 minutes lost in 525.887 minutes! It's 0.002%..</h5>","metadata":{}},{"cell_type":"code","source":"# Let's mask it to see which part of time has a problem\nmask = train.index.to_series().diff() != pd.Timedelta(\"1min\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:00.800858Z","iopub.execute_input":"2025-06-19T11:28:00.801153Z","iopub.status.idle":"2025-06-19T11:28:00.817338Z","shell.execute_reply.started":"2025-06-19T11:28:00.801131Z","shell.execute_reply":"2025-06-19T11:28:00.816255Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.index.to_series().diff()[mask]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:00.818519Z","iopub.execute_input":"2025-06-19T11:28:00.818856Z","iopub.status.idle":"2025-06-19T11:28:00.837277Z","shell.execute_reply.started":"2025-06-19T11:28:00.818828Z","shell.execute_reply":"2025-06-19T11:28:00.836338Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h5 style=\"text-align:center; color:yellow\">Only 274 lines are different than 1 minute (If we don't count the first one).\nLet's check if this information is true.</h5>","metadata":{}},{"cell_type":"code","source":"train.loc['2023-04-08 08:29:00':'2023-04-08 08:31:00']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:00.838487Z","iopub.execute_input":"2025-06-19T11:28:00.838830Z","iopub.status.idle":"2025-06-19T11:28:00.887066Z","shell.execute_reply.started":"2025-06-19T11:28:00.838801Z","shell.execute_reply":"2025-06-19T11:28:00.885806Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h5 style=\"text-align:center; color:yellow\">There is a really 2 minutes gap.\n</h5>","metadata":{}},{"cell_type":"code","source":"train.loc['2023-04-10 02:41:00':'2023-04-10 03:00:00']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:00.888413Z","iopub.execute_input":"2025-06-19T11:28:00.888713Z","iopub.status.idle":"2025-06-19T11:28:00.919286Z","shell.execute_reply.started":"2025-06-19T11:28:00.888689Z","shell.execute_reply":"2025-06-19T11:28:00.917713Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h5 style=\"text-align:center; color:yellow\">There is an 18-minute gap!</h5>","metadata":{}},{"cell_type":"markdown","source":"<h2 style=\"text-align:center; color:pink\">Before filling the NaNs, lastly, look at a plot.\n</h2>","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(10,5))\nplt.plot(train.index, train[\"bid_qty\"], linestyle=\"-\", linewidth=0.3)\nplt.grid(True)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:00.920716Z","iopub.execute_input":"2025-06-19T11:28:00.921109Z","iopub.status.idle":"2025-06-19T11:28:01.515867Z","shell.execute_reply.started":"2025-06-19T11:28:00.921074Z","shell.execute_reply":"2025-06-19T11:28:01.514752Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(10,5))\nplt.plot(train.index, train[\"label\"], linestyle=\"-\", linewidth=0.3)\nplt.grid(True)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:01.516957Z","iopub.execute_input":"2025-06-19T11:28:01.517270Z","iopub.status.idle":"2025-06-19T11:28:01.869163Z","shell.execute_reply.started":"2025-06-19T11:28:01.517249Z","shell.execute_reply":"2025-06-19T11:28:01.868219Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h5 style=\"text-align:center; color:yellow\">OKAY! That's enough to analyze.</h5>","metadata":{}},{"cell_type":"markdown","source":"<h2 style=\"text-align:center; color:pink\">Let's fill in the blanks.</h2>","metadata":{}},{"cell_type":"code","source":"train.isna().sum().value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:01.870352Z","iopub.execute_input":"2025-06-19T11:28:01.870631Z","iopub.status.idle":"2025-06-19T11:28:03.550483Z","shell.execute_reply.started":"2025-06-19T11:28:01.870611Z","shell.execute_reply":"2025-06-19T11:28:03.549764Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"full_index = pd.date_range(start=train.index.min(), end=train.index.max(), freq='T')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:03.551459Z","iopub.execute_input":"2025-06-19T11:28:03.551670Z","iopub.status.idle":"2025-06-19T11:28:03.557434Z","shell.execute_reply.started":"2025-06-19T11:28:03.551654Z","shell.execute_reply":"2025-06-19T11:28:03.556517Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_full = train.reindex(full_index)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:03.558412Z","iopub.execute_input":"2025-06-19T11:28:03.558703Z","iopub.status.idle":"2025-06-19T11:28:06.214973Z","shell.execute_reply.started":"2025-06-19T11:28:03.558673Z","shell.execute_reply":"2025-06-19T11:28:06.213564Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"rolling_means = df_full.rolling(window=12000, min_periods=1).mean()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:06.216265Z","iopub.execute_input":"2025-06-19T11:28:06.216613Z","iopub.status.idle":"2025-06-19T11:28:30.338304Z","shell.execute_reply.started":"2025-06-19T11:28:06.216584Z","shell.execute_reply":"2025-06-19T11:28:30.337141Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_filled = df_full.fillna(rolling_means)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:30.339533Z","iopub.execute_input":"2025-06-19T11:28:30.339920Z","iopub.status.idle":"2025-06-19T11:28:35.255286Z","shell.execute_reply.started":"2025-06-19T11:28:30.339876Z","shell.execute_reply":"2025-06-19T11:28:35.254288Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train.shape)\nprint(1426 + train.shape[0])\ntrain_filled.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:35.256541Z","iopub.execute_input":"2025-06-19T11:28:35.256859Z","iopub.status.idle":"2025-06-19T11:28:35.265487Z","shell.execute_reply.started":"2025-06-19T11:28:35.256825Z","shell.execute_reply":"2025-06-19T11:28:35.264580Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_filled.isna().sum().value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:35.266480Z","iopub.execute_input":"2025-06-19T11:28:35.267144Z","iopub.status.idle":"2025-06-19T11:28:36.976723Z","shell.execute_reply.started":"2025-06-19T11:28:35.267109Z","shell.execute_reply":"2025-06-19T11:28:36.975341Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"del train\ndel df_full\ndel full_index\ndel rolling_means","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:36.982855Z","iopub.execute_input":"2025-06-19T11:28:36.983298Z","iopub.status.idle":"2025-06-19T11:28:37.014106Z","shell.execute_reply.started":"2025-06-19T11:28:36.983274Z","shell.execute_reply":"2025-06-19T11:28:37.013105Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"nan_rows = train_filled[train_filled.isna().any(axis=1)]\nnan_rows.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:37.015031Z","iopub.execute_input":"2025-06-19T11:28:37.015550Z","iopub.status.idle":"2025-06-19T11:28:38.371530Z","shell.execute_reply.started":"2025-06-19T11:28:37.015511Z","shell.execute_reply":"2025-06-19T11:28:38.369805Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"nan_columns = train_filled.columns[train_filled.isna().any()].tolist()\nprint(nan_columns)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:38.372710Z","iopub.execute_input":"2025-06-19T11:28:38.373013Z","iopub.status.idle":"2025-06-19T11:28:39.665804Z","shell.execute_reply.started":"2025-06-19T11:28:38.372982Z","shell.execute_reply":"2025-06-19T11:28:39.664742Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train_filled[\"X696\"][0])\nprint(train_filled[\"X697\"][0])\nprint(train_filled[\"X698\"][0])\nprint(train_filled[\"X698\"][1])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:39.666681Z","iopub.execute_input":"2025-06-19T11:28:39.666936Z","iopub.status.idle":"2025-06-19T11:28:39.673514Z","shell.execute_reply.started":"2025-06-19T11:28:39.666916Z","shell.execute_reply":"2025-06-19T11:28:39.672458Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"nan_rows[\"X697\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:39.674516Z","iopub.execute_input":"2025-06-19T11:28:39.674778Z","iopub.status.idle":"2025-06-19T11:28:39.700415Z","shell.execute_reply.started":"2025-06-19T11:28:39.674758Z","shell.execute_reply":"2025-06-19T11:28:39.699097Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"nan_rows[\"X698\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:39.701669Z","iopub.execute_input":"2025-06-19T11:28:39.701991Z","iopub.status.idle":"2025-06-19T11:28:39.723149Z","shell.execute_reply.started":"2025-06-19T11:28:39.701965Z","shell.execute_reply":"2025-06-19T11:28:39.722171Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_filled.dtypes.value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:39.724141Z","iopub.execute_input":"2025-06-19T11:28:39.724496Z","iopub.status.idle":"2025-06-19T11:28:39.750993Z","shell.execute_reply.started":"2025-06-19T11:28:39.724466Z","shell.execute_reply":"2025-06-19T11:28:39.749904Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h5 style=\"text-align:center; color:yellow\">Because the -inf value is outside the range of -1.8e308 to +1.8e308, Python automatically fills it with -inf. This means 308 more digits after the decimal point, followed by 1.8. <br><br> It's because of my filling strategy.</h5>","metadata":{}},{"cell_type":"markdown","source":"<h5 style=\"text-align:center; color:yellow\">Some experiments of \"inf\"</h5>","metadata":{}},{"cell_type":"code","source":"import sys\nsys.float_info","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:39.752223Z","iopub.execute_input":"2025-06-19T11:28:39.752585Z","iopub.status.idle":"2025-06-19T11:28:39.775574Z","shell.execute_reply.started":"2025-06-19T11:28:39.752535Z","shell.execute_reply":"2025-06-19T11:28:39.774264Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(1.8e308) \nprint(-1.8e308)  ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:39.776774Z","iopub.execute_input":"2025-06-19T11:28:39.777244Z","iopub.status.idle":"2025-06-19T11:28:39.797932Z","shell.execute_reply.started":"2025-06-19T11:28:39.777211Z","shell.execute_reply":"2025-06-19T11:28:39.796957Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"a = 1.8e308\nprint(a)","metadata":{"execution":{"iopub.status.busy":"2025-06-19T11:28:39.799397Z","iopub.execute_input":"2025-06-19T11:28:39.799688Z","iopub.status.idle":"2025-06-19T11:28:39.820435Z","shell.execute_reply.started":"2025-06-19T11:28:39.799667Z","shell.execute_reply":"2025-06-19T11:28:39.819467Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\n\na = 1.8e308         \nb = np.float128(a)  \n\nprint(b)           ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:39.821590Z","iopub.execute_input":"2025-06-19T11:28:39.821905Z","iopub.status.idle":"2025-06-19T11:28:39.846324Z","shell.execute_reply.started":"2025-06-19T11:28:39.821871Z","shell.execute_reply":"2025-06-19T11:28:39.844924Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h1 style=\"text-align:center; color:pink\">M A K E &nbsp R E A D Y &nbsp O U R &nbsp D A T A</h1>","metadata":{}},{"cell_type":"markdown","source":"#### We are going to use the Xgboost model so we will make:","metadata":{}},{"cell_type":"code","source":"train_filled.drop(nan_columns, axis=1, inplace=True)\ntest.drop(nan_columns, axis=1, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:39.847744Z","iopub.execute_input":"2025-06-19T11:28:39.848071Z","iopub.status.idle":"2025-06-19T11:28:42.996493Z","shell.execute_reply.started":"2025-06-19T11:28:39.848020Z","shell.execute_reply":"2025-06-19T11:28:42.995492Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from xgboost import XGBRegressor\nfrom sklearn.metrics import mean_squared_error","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:42.997555Z","iopub.execute_input":"2025-06-19T11:28:42.997810Z","iopub.status.idle":"2025-06-19T11:28:44.969764Z","shell.execute_reply.started":"2025-06-19T11:28:42.997789Z","shell.execute_reply":"2025-06-19T11:28:44.968533Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_size = int(len(train_filled) * 0.8)\nprint((train_size))\n\ntrain_set = train_filled.iloc[:train_size]\ntest_set = train_filled.iloc[train_size:]\nprint(train_set.shape)\nprint(test_set.shape)\nprint(\"------------- \\n\")\n\ny_train = train_set['label']\nX_train = train_set.drop('label', axis=1)\nprint(y_train.shape)\nprint(X_train.shape)\nprint(\"------------- \\n\")\n\ny_test = test_set['label']\nX_test = test_set.drop('label', axis=1)\nprint(y_test.shape)\nprint(X_test.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:44.971188Z","iopub.execute_input":"2025-06-19T11:28:44.971669Z","iopub.status.idle":"2025-06-19T11:28:46.247570Z","shell.execute_reply.started":"2025-06-19T11:28:44.971633Z","shell.execute_reply":"2025-06-19T11:28:46.246456Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(X_train.shape)\nprint(X_test.shape)\nprint(y_train.shape)\nprint(y_test.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:46.248849Z","iopub.execute_input":"2025-06-19T11:28:46.249227Z","iopub.status.idle":"2025-06-19T11:28:46.255075Z","shell.execute_reply.started":"2025-06-19T11:28:46.249188Z","shell.execute_reply":"2025-06-19T11:28:46.254206Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = XGBRegressor(\n    n_estimators=100,       \n    learning_rate=0.05,     \n)\n\nmodel.fit(\n    X_train, y_train,\n    eval_set=[(X_test, y_test)],\n    early_stopping_rounds=1,    \n    verbose=2                   \n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:28:46.256077Z","iopub.execute_input":"2025-06-19T11:28:46.256364Z","iopub.status.idle":"2025-06-19T11:29:40.198106Z","shell.execute_reply.started":"2025-06-19T11:28:46.256343Z","shell.execute_reply":"2025-06-19T11:29:40.197144Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred = model.predict(X_test)\ny_pred","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:29:40.199308Z","iopub.execute_input":"2025-06-19T11:29:40.199591Z","iopub.status.idle":"2025-06-19T11:29:40.625080Z","shell.execute_reply.started":"2025-06-19T11:29:40.199568Z","shell.execute_reply":"2025-06-19T11:29:40.623255Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"mse = mean_squared_error(y_test, y_pred)\nprint(f\"Test MSE: {mse:.4f}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:29:40.625919Z","iopub.execute_input":"2025-06-19T11:29:40.626204Z","iopub.status.idle":"2025-06-19T11:29:40.642829Z","shell.execute_reply.started":"2025-06-19T11:29:40.626184Z","shell.execute_reply":"2025-06-19T11:29:40.641585Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from xgboost import plot_importance\n\n# Show top 20 features by gain\nplot_importance(model, importance_type='gain', max_num_features=20, height=0.5)\nplt.title(\"XGBoost - Most Important 20 Features (Gain)\")\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:29:40.644571Z","iopub.execute_input":"2025-06-19T11:29:40.645064Z","iopub.status.idle":"2025-06-19T11:29:41.102187Z","shell.execute_reply.started":"2025-06-19T11:29:40.645005Z","shell.execute_reply":"2025-06-19T11:29:41.100929Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.plot(y_test.values, label='Real')\nplt.plot(y_pred, label='Predicted')\nplt.legend()\nplt.title(\"Real vs Predict\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:29:41.103086Z","iopub.execute_input":"2025-06-19T11:29:41.103433Z","iopub.status.idle":"2025-06-19T11:29:41.466777Z","shell.execute_reply.started":"2025-06-19T11:29:41.103404Z","shell.execute_reply":"2025-06-19T11:29:41.465675Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h2 style=\"text-align:center; color:pink\">Submission</h2>","metadata":{}},{"cell_type":"code","source":"test.drop([\"label\"], axis=1, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:29:41.467875Z","iopub.execute_input":"2025-06-19T11:29:41.468207Z","iopub.status.idle":"2025-06-19T11:29:43.716986Z","shell.execute_reply.started":"2025-06-19T11:29:41.468175Z","shell.execute_reply":"2025-06-19T11:29:43.716115Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(test.shape)\ntest.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:29:43.718103Z","iopub.execute_input":"2025-06-19T11:29:43.718398Z","iopub.status.idle":"2025-06-19T11:29:43.743593Z","shell.execute_reply.started":"2025-06-19T11:29:43.718378Z","shell.execute_reply":"2025-06-19T11:29:43.741921Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predictions = model.predict(test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:29:43.744692Z","iopub.execute_input":"2025-06-19T11:29:43.745011Z","iopub.status.idle":"2025-06-19T11:29:46.760769Z","shell.execute_reply.started":"2025-06-19T11:29:43.744979Z","shell.execute_reply":"2025-06-19T11:29:46.760110Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(len(sub))\nprint(len(predictions))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:29:46.761384Z","iopub.execute_input":"2025-06-19T11:29:46.761605Z","iopub.status.idle":"2025-06-19T11:29:46.765397Z","shell.execute_reply.started":"2025-06-19T11:29:46.761587Z","shell.execute_reply":"2025-06-19T11:29:46.764679Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sub","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:29:46.766815Z","iopub.execute_input":"2025-06-19T11:29:46.767612Z","iopub.status.idle":"2025-06-19T11:29:46.798641Z","shell.execute_reply.started":"2025-06-19T11:29:46.767588Z","shell.execute_reply":"2025-06-19T11:29:46.797204Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sub[\"prediction\"] = predictions","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:29:46.799979Z","iopub.execute_input":"2025-06-19T11:29:46.800462Z","iopub.status.idle":"2025-06-19T11:29:46.821689Z","shell.execute_reply.started":"2025-06-19T11:29:46.800425Z","shell.execute_reply":"2025-06-19T11:29:46.820408Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sub","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:29:46.822806Z","iopub.execute_input":"2025-06-19T11:29:46.823214Z","iopub.status.idle":"2025-06-19T11:29:46.849410Z","shell.execute_reply.started":"2025-06-19T11:29:46.823184Z","shell.execute_reply":"2025-06-19T11:29:46.848468Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sub.to_csv(\"submission.csv\", index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-19T11:29:46.850485Z","iopub.execute_input":"2025-06-19T11:29:46.850782Z","iopub.status.idle":"2025-06-19T11:29:47.833856Z","shell.execute_reply.started":"2025-06-19T11:29:46.850761Z","shell.execute_reply":"2025-06-19T11:29:47.832841Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h1 style=\"text-align:center; color:pink\">What you can try next time?</h1>","metadata":{}},{"cell_type":"markdown","source":"<h4 style=\"text-align: justify\">\n This notebook was only for beginners to have a better understanding of the logic of submission. This provides an example template for the next submission. I hope this helps you. I wrote a lot of code in an inefficient way because I want you to understand what could be better while you are examining the notebook.\n</h4>\n\n<h4 style=\"text-align: justify\">\nNext time, we can change our features (we can add extra features or just remove some things), our model, our parameters of the model... For now, let's deal with these 3 titles. If you find something better, you can share it with me! I hope you enjoy your Kaggle Journey. \n</h4>","metadata":{}},{"cell_type":"markdown","source":"<h3 style=\"text-align:center; color:blue; font-size:60px\">May everything be as you wish.</h3>","metadata":{}}]}