{"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":"## Goals per event?? \n## Distance to goal (via ball position)","metadata":{"execution":{"iopub.status.busy":"2022-10-10T12:12:05.632868Z","iopub.execute_input":"2022-10-10T12:12:05.633952Z","iopub.status.idle":"2022-10-10T12:12:05.640474Z","shell.execute_reply.started":"2022-10-10T12:12:05.633901Z","shell.execute_reply":"2022-10-10T12:12:05.639532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 🏆Summary 🏆\nIn this tabular playground, we are asked to predict the probability of each rocket league team (team A and B) scoring in the next 10 secs, using information regarding the:\n* Players & Teams\n* Ball (velocity, position etc)\n* Event (boost timer, id, etc)","metadata":{}},{"cell_type":"markdown","source":"### Data columns\n\n* **game_num** (train only): Unique identifier for the game from which the event was taken.\n\n* **event_id** (train only): Unique identifier for the sequence of consecutive frames.\n\n* **event_time** (train only): Time in seconds before the event ended, either by a goal being scored or simply when we decided to truncate the timeseries if a goal was not scored.\n\n* **ball_pos_[xyz]**: Ball's position as a 3d vector.\n\n* **ball_vel_[xyz]**: Ball's velocity as a 3d vector.\n\n* For i in [0, 6):\n\n    *  **p{i}_pos_[xyz]**: Player i's position as a 3d vector.\n    *  **p{i}_vel_[xyz]**: Player i's velocity as a 3d vector.\n    *  **p{i}_boost**: Player i's boost remaining, in [0, 100]. A player can consume boost to substantially increase their speed, and is required to fly up into the z dimension (besides driving up a wall, or the small air gained by a jump).\n    * All p{i} columns will be **NaN** if and only if the player is **demolished** (destroyed by an enemy player; will respawn within a few seconds).\n    * Players 0, 1, and 2 make up **team A** and players 3, 4, and 5 make up **team B**.\n    * The orientation vector of the player's car (which way the car is facing) does not necessarily match the player's velocity vector, and this dataset does not capture orientation data.\n\n* For i in [0, 6):\n\n    * **boost{i}_timer**: Time in seconds until big boost orb i respawns, or 0 if it's available. Big boost orbs grant a full 100 boost to a player driving over it. The orb (x, y) locations are roughly [ (-61.4, -81.9), (61.4, -81.9), (-71.7, 0), (71.7, 0), (-61.4, 81.9), (61.4, 81.9) ] with z = 0. (Players can also gain boost from small boost pads across the map, but we do not capture those pads in this dataset).\n* **player_scoring_next** (train only): Which player scores at the end of the current event, in [0, 6), or -1 if the event does not end in a goal.\n\n* **team_scoring_next** (train only): Which team scores at the end of the current event (A or B), or NaN if the event does not end in a goal.\n\n* **team_[A|B]_scoring_within_10sec** (train only): [Target columns] Value of 1 if team_scoring_next == [A|B] and time_before_event is in [-10, 0], otherwise 0.\n\n* **id** (test and submission only): Unique identifier for each test row. Your submission should be a pair of team_A_scoring_within_10sec and team_B_scoring_within_10sec probability predictions for each id, where your predictions can range the real numbers from [0, 1].","metadata":{}},{"cell_type":"markdown","source":"# Import Libraries & Data ","metadata":{}},{"cell_type":"code","source":"import numpy as np \nimport pandas as pd\nimport seaborn as sns \nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-10-10T12:12:05.643289Z","iopub.execute_input":"2022-10-10T12:12:05.643748Z","iopub.status.idle":"2022-10-10T12:12:05.655449Z","shell.execute_reply.started":"2022-10-10T12:12:05.643705Z","shell.execute_reply":"2022-10-10T12:12:05.654082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"##Train 0 \ntrn_dtypes = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/train_dtypes.csv')\ntrn_dtypes_dict = {k: v for (k, v) in zip(trn_dtypes.column, trn_dtypes.dtype)}\ntrain0 = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/train_0.csv', dtype=trn_dtypes_dict)\n\n##Test\ntst_dtypes = pd.read_csv('../input/tabular-playground-series-oct-2022/test_dtypes.csv')\ntst_dtypes_dict = {k: v for (k, v) in zip(tst_dtypes.column, tst_dtypes.dtype)}\ntest = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/train_0.csv', dtype=tst_dtypes_dict)\n\n# Sub \nsub = pd.read_csv(\"../input/tabular-playground-series-oct-2022/sample_submission.csv\",index_col = 0)","metadata":{"execution":{"iopub.status.busy":"2022-10-10T12:12:05.657074Z","iopub.execute_input":"2022-10-10T12:12:05.657704Z","iopub.status.idle":"2022-10-10T12:12:42.526307Z","shell.execute_reply.started":"2022-10-10T12:12:05.657662Z","shell.execute_reply":"2022-10-10T12:12:42.525027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2022-10-10T12:12:42.527706Z","iopub.execute_input":"2022-10-10T12:12:42.528523Z","iopub.status.idle":"2022-10-10T12:12:42.975053Z","shell.execute_reply.started":"2022-10-10T12:12:42.528485Z","shell.execute_reply":"2022-10-10T12:12:42.973630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0","metadata":{"execution":{"iopub.status.busy":"2022-10-10T12:12:42.978051Z","iopub.execute_input":"2022-10-10T12:12:42.978377Z","iopub.status.idle":"2022-10-10T12:12:43.269937Z","shell.execute_reply.started":"2022-10-10T12:12:42.978348Z","shell.execute_reply":"2022-10-10T12:12:43.268855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0.groupby([\"game_num\",\"event_id\"]).sum()[\"team_A_scoring_within_10sec\"]","metadata":{"execution":{"iopub.status.busy":"2022-10-10T12:12:43.271450Z","iopub.execute_input":"2022-10-10T12:12:43.271897Z","iopub.status.idle":"2022-10-10T12:12:44.827011Z","shell.execute_reply.started":"2022-10-10T12:12:43.271860Z","shell.execute_reply":"2022-10-10T12:12:44.825871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0.groupby([\"game_num\",\"event_id\"]).max()[\"team_A_scoring_within_10sec\"]","metadata":{"execution":{"iopub.status.busy":"2022-10-10T12:12:44.828496Z","iopub.execute_input":"2022-10-10T12:12:44.829276Z","iopub.status.idle":"2022-10-10T12:12:46.736729Z","shell.execute_reply.started":"2022-10-10T12:12:44.829232Z","shell.execute_reply":"2022-10-10T12:12:46.735620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Target Column \nWe are asked to predict the probability of team A **AND** team B scoring, where we have 2 columns for this purpose: \n* team_A_scoring_within_10sec\n* team_B_scoring_within_10sec\n\nWe therefore have 2 options:\n1. Merge the two columns and make a categorical column: \n    * 0 = no team to score\n    * 1 = Team A to score\n    * 2 = Team B to score\n2. Predict each column seperately ","metadata":{}},{"cell_type":"code","source":"fig,ax = plt.subplots(1,2,figsize = (20,5))\nsns.countplot(ax = ax[0], x= train0[\"team_A_scoring_within_10sec\"])\nsns.countplot(ax = ax[1], x= train0[\"team_B_scoring_within_10sec\"])\nax[0].set_title(\"Team A to score count\")\nax[1].set_title(\"Team B to score count\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-10T12:12:46.738122Z","iopub.execute_input":"2022-10-10T12:12:46.738464Z","iopub.status.idle":"2022-10-10T12:12:47.323715Z","shell.execute_reply.started":"2022-10-10T12:12:46.738434Z","shell.execute_reply":"2022-10-10T12:12:47.322494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Nulls ","metadata":{}},{"cell_type":"code","source":"train0.isnull().sum()[train0.isnull().sum()>0]","metadata":{"execution":{"iopub.status.busy":"2022-10-10T12:12:47.325737Z","iopub.execute_input":"2022-10-10T12:12:47.326216Z","iopub.status.idle":"2022-10-10T12:12:48.078952Z","shell.execute_reply.started":"2022-10-10T12:12:47.326173Z","shell.execute_reply":"2022-10-10T12:12:48.077825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plot ball position","metadata":{"execution":{"iopub.status.busy":"2022-10-03T11:42:56.924135Z","iopub.execute_input":"2022-10-03T11:42:56.924711Z","iopub.status.idle":"2022-10-03T11:42:56.929722Z","shell.execute_reply.started":"2022-10-03T11:42:56.924662Z","shell.execute_reply":"2022-10-03T11:42:56.928697Z"}}},{"cell_type":"code","source":"train0[\"Target\"] = train0[\"team_A_scoring_within_10sec\"].astype(str)+train0[\"team_B_scoring_within_10sec\"].astype(str)\ntrain0[\"Target\"] =train0[\"Target\"].map({\"00\":\"no goal\", \"10\":\"Team A goal\",\"01\":\"Team B goal\"})\n# team_scores = train0[(train0[\"team_A_scoring_within_10sec\"]!=0) | (train0[\"team_B_scoring_within_10sec\"]!=0)]\n# teamA_scores = train0[train0[\"team_A_scoring_within_10sec\"]!=0]\n# teamB_scores = train0[train0[\"team_B_scoring_within_10sec\"]!=0]","metadata":{"execution":{"iopub.status.busy":"2022-10-10T12:12:48.080610Z","iopub.execute_input":"2022-10-10T12:12:48.081080Z","iopub.status.idle":"2022-10-10T12:12:48.242614Z","shell.execute_reply.started":"2022-10-10T12:12:48.081039Z","shell.execute_reply":"2022-10-10T12:12:48.241561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20,20))\nsns.scatterplot(x = train0[\"ball_pos_x\"], y = train0[\"ball_pos_y\"],hue = train0['Target']  )\nplt.title(\"Ball position vs goal/no goal in next 10secs\")\nplt.legend(loc='upper right')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-10T12:17:52.850657Z","iopub.execute_input":"2022-10-10T12:17:52.851068Z","iopub.status.idle":"2022-10-10T12:18:37.532074Z","shell.execute_reply.started":"2022-10-10T12:17:52.851030Z","shell.execute_reply":"2022-10-10T12:18:37.531137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20,10))\nsns.scatterplot(x = train0[train0[\"game_num\"]==2][\"ball_pos_y\"], y = train0[train0[\"game_num\"]==2][\"ball_pos_x\"],hue = train0[train0[\"game_num\"]==2]['team_B_scoring_within_10sec']  )\nplt.title(\"Game 2: ball position vs goal/no goal in next 10secs\")\nplt.legend(loc='upper right')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-10T12:20:34.332458Z","iopub.execute_input":"2022-10-10T12:20:34.333559Z","iopub.status.idle":"2022-10-10T12:20:34.842865Z","shell.execute_reply.started":"2022-10-10T12:20:34.333521Z","shell.execute_reply":"2022-10-10T12:20:34.841809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can see the pitch using the above.  \nThis gives us an indication of the where the goals are \n\n* goal1_location = (0,100,0) #assumption that goal centre is at z= 0 (unknown how high the goal is)\n* goal2_location = (0,-100,0) ","metadata":{}},{"cell_type":"markdown","source":"# Player position","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize = (20,15))\nsns.scatterplot(x = train0[\"p0_pos_x\"], y = train0[\"p0_pos_y\"],hue = train0['Target']  )\nplt.legend(loc='upper right')\nplt.title(\"player 0 (Team A) position vs goal/no goal in next 10secs\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-10T12:19:06.572883Z","iopub.execute_input":"2022-10-10T12:19:06.574014Z","iopub.status.idle":"2022-10-10T12:19:50.378371Z","shell.execute_reply.started":"2022-10-10T12:19:06.573969Z","shell.execute_reply":"2022-10-10T12:19:50.377123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20,15))\nsns.scatterplot(x = train0[\"p5_pos_x\"], y = train0[\"p5_pos_y\"],hue = train0['Target']  )\nplt.legend(loc='upper right')\nplt.title(\"player 5  (Team B) position vs goal/no goal in next 10secs\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-10T12:19:50.380582Z","iopub.execute_input":"2022-10-10T12:19:50.381353Z","iopub.status.idle":"2022-10-10T12:20:34.330884Z","shell.execute_reply.started":"2022-10-10T12:19:50.381296Z","shell.execute_reply":"2022-10-10T12:20:34.329818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}