{"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 pandas as pd\nfrom tqdm import tqdm\nfrom matplotlib import pyplot as plt\nimport seaborn as sns","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-10-01T21:15:48.980740Z","iopub.execute_input":"2022-10-01T21:15:48.981462Z","iopub.status.idle":"2022-10-01T21:15:50.099776Z","shell.execute_reply.started":"2022-10-01T21:15:48.981366Z","shell.execute_reply":"2022-10-01T21:15:50.098862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dtypes_df = pd.read_csv('../input/tabular-playground-series-oct-2022/train_dtypes.csv')\ntrain_dtypes = {k: v for (k, v) in zip(train_dtypes_df.column, train_dtypes_df.dtype)}","metadata":{"execution":{"iopub.status.busy":"2022-10-01T21:15:50.101437Z","iopub.execute_input":"2022-10-01T21:15:50.101776Z","iopub.status.idle":"2022-10-01T21:15:50.126656Z","shell.execute_reply.started":"2022-10-01T21:15:50.101744Z","shell.execute_reply":"2022-10-01T21:15:50.125585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"event_times = pd.DataFrame(columns=['event_time'], dtype='float32')\nfor i in tqdm(range(10)):\n    temp_df = pd.read_csv('../input/tabular-playground-series-oct-2022/train_{}.csv'.format(i))\n    event_times = pd.concat([event_times, temp_df[[\"event_id\", \"event_time\"]].groupby(\"event_id\").min()], axis=0)\nevent_times = event_times.apply(lambda x: abs(x))","metadata":{"execution":{"iopub.status.busy":"2022-10-01T10:57:47.803859Z","iopub.execute_input":"2022-10-01T10:57:47.804516Z","iopub.status.idle":"2022-10-01T11:02:31.535206Z","shell.execute_reply.started":"2022-10-01T10:57:47.804481Z","shell.execute_reply":"2022-10-01T11:02:31.533770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(event_times, aspect=2)","metadata":{"execution":{"iopub.status.busy":"2022-10-01T11:35:35.784378Z","iopub.execute_input":"2022-10-01T11:35:35.784894Z","iopub.status.idle":"2022-10-01T11:35:36.618210Z","shell.execute_reply.started":"2022-10-01T11:35:35.784853Z","shell.execute_reply":"2022-10-01T11:35:36.617057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_header = pd.read_csv('../input/tabular-playground-series-oct-2022/train_0.csv', nrows=0)\ntest_header = pd.read_csv('../input/tabular-playground-series-oct-2022/test.csv', nrows=0)\n\nprint(\"Train only features: \", [i for i in train_header.columns if i not in test_header.columns])","metadata":{"execution":{"iopub.status.busy":"2022-10-01T16:01:19.349595Z","iopub.execute_input":"2022-10-01T16:01:19.350008Z","iopub.status.idle":"2022-10-01T16:01:19.358520Z","shell.execute_reply.started":"2022-10-01T16:01:19.349973Z","shell.execute_reply":"2022-10-01T16:01:19.357227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Observations**\n* In addition to the target features `['team_A_scoring_within_10sec', 'team_B_scoring_within_10sec']` there are extra columns that are not available within the test set, so they cannot be used in modeling","metadata":{}},{"cell_type":"markdown","source":"Only `train_0.csv` dataset will be used in further analysis To speed up data exploration process","metadata":{}},{"cell_type":"code","source":"train0 = pd.read_csv('../input/tabular-playground-series-oct-2022/train_0.csv', dtype=train_dtypes)\ntrain0[\"score_team\"] = train0.apply(lambda x: \"A\" if x.team_A_scoring_within_10sec else (\"B\" if x.team_B_scoring_within_10sec else \"None\"), axis=1)\ntrain0_filtered = train0[train0[\"score_team\"] != \"None\"]","metadata":{"execution":{"iopub.status.busy":"2022-10-01T21:16:06.208239Z","iopub.execute_input":"2022-10-01T21:16:06.209347Z","iopub.status.idle":"2022-10-01T21:16:06.454794Z","shell.execute_reply.started":"2022-10-01T21:16:06.209307Z","shell.execute_reply":"2022-10-01T21:16:06.453119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, axs = plt.subplots(3, 1, figsize=(15, 15))\n\nsns.histplot(data=train0_filtered, x=\"ball_pos_z\", hue=\"score_team\", ax=axs[0])\nsns.histplot(data=train0_filtered, x=\"ball_pos_x\", hue=\"score_team\", ax=axs[1])\nsns.histplot(data=train0_filtered, x=\"ball_pos_y\", hue=\"score_team\", ax=axs[2])","metadata":{"execution":{"iopub.status.busy":"2022-10-01T20:10:46.073883Z","iopub.execute_input":"2022-10-01T20:10:46.074393Z","iopub.status.idle":"2022-10-01T20:10:48.597684Z","shell.execute_reply.started":"2022-10-01T20:10:46.074343Z","shell.execute_reply":"2022-10-01T20:10:48.596485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Observations:**\n* `team_A_scoring_within_10sec` and `team_B_scoring_within_10sec` have different `ball_pos_y` distribution, team A distribution is right skewed and team B is left skewed ","metadata":{}},{"cell_type":"code","source":"fig, axs = plt.subplots(1, 3, figsize=(24, 8))\n\nsns.scatterplot(data=train0_filtered, x=\"ball_pos_x\", y=\"ball_pos_y\", hue=\"score_team\", ax=axs[0], s=5)\nsns.scatterplot(data=train0_filtered, x=\"ball_pos_x\", y=\"ball_pos_z\", hue=\"score_team\", ax=axs[1], s=5)\nsns.scatterplot(data=train0_filtered, x=\"ball_pos_z\", y=\"ball_pos_y\", hue=\"score_team\", ax=axs[2], s=5)","metadata":{"execution":{"iopub.status.busy":"2022-10-01T20:04:24.451330Z","iopub.execute_input":"2022-10-01T20:04:24.451818Z","iopub.status.idle":"2022-10-01T20:05:10.540060Z","shell.execute_reply.started":"2022-10-01T20:04:24.451781Z","shell.execute_reply":"2022-10-01T20:05:10.538678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Observations:**\n* It seems that ball y position is the only coordinate that helps in predicting if a team will score within 10 sec","metadata":{}},{"cell_type":"code","source":"fig, axs = plt.subplots(3, 1, figsize=(15, 15))\n\nsns.histplot(data=train0_filtered, x=\"ball_vel_z\", hue=\"score_team\", ax=axs[0])\nsns.histplot(data=train0_filtered, x=\"ball_vel_x\", hue=\"score_team\", ax=axs[1])\nsns.histplot(data=train0_filtered, x=\"ball_vel_y\", hue=\"score_team\", ax=axs[2])","metadata":{"execution":{"iopub.status.busy":"2022-10-01T20:22:06.883289Z","iopub.execute_input":"2022-10-01T20:22:06.884054Z","iopub.status.idle":"2022-10-01T20:22:10.947274Z","shell.execute_reply.started":"2022-10-01T20:22:06.883993Z","shell.execute_reply":"2022-10-01T20:22:10.946181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, axs = plt.subplots(1, 3, figsize=(24, 8))\n\nsns.scatterplot(data=train0_filtered, x=\"ball_vel_x\", y=\"ball_vel_y\", hue=\"score_team\", ax=axs[0], s=5)\nsns.scatterplot(data=train0_filtered, x=\"ball_vel_x\", y=\"ball_vel_z\", hue=\"score_team\", ax=axs[1], s=5)\nsns.scatterplot(data=train0_filtered, x=\"ball_vel_z\", y=\"ball_vel_y\", hue=\"score_team\", ax=axs[2], s=5)","metadata":{"execution":{"iopub.status.busy":"2022-10-01T20:22:51.444821Z","iopub.execute_input":"2022-10-01T20:22:51.445307Z","iopub.status.idle":"2022-10-01T20:23:15.094501Z","shell.execute_reply.started":"2022-10-01T20:22:51.445266Z","shell.execute_reply":"2022-10-01T20:23:15.093257Z"},"trusted":true},"execution_count":null,"outputs":[]}]}