{"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)\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-10-17T10:33:08.577064Z","iopub.execute_input":"2022-10-17T10:33:08.577454Z","iopub.status.idle":"2022-10-17T10:33:08.585363Z","shell.execute_reply.started":"2022-10-17T10:33:08.577419Z","shell.execute_reply":"2022-10-17T10:33:08.584549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np  # linear algebra\nimport pandas as pd  # data manipulation\nimport os  # file navigation\nimport gc  # garbage collection\n\n# visualization\nimport plotly.express as px\nimport plotly.graph_objects as go\nfrom plotly import subplots\n\nfrom sklearn.model_selection import cross_validate  # k-fold Cross Validation\nfrom sklearn.preprocessing import LabelEncoder  # output binary encoding\n\nfrom xgboost import XGBClassifier  # Gradient Boosted Tree (XGBoost)\n\nfrom tensorflow.config import list_physical_devices  # check if GPU is available","metadata":{"execution":{"iopub.status.busy":"2022-10-17T10:33:08.981744Z","iopub.execute_input":"2022-10-17T10:33:08.982342Z","iopub.status.idle":"2022-10-17T10:33:15.904324Z","shell.execute_reply.started":"2022-10-17T10:33:08.982307Z","shell.execute_reply":"2022-10-17T10:33:15.903281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# training and cross validation\nGPU = list_physical_devices('GPU') != []\nN_ESTIMATORS = 2000\nMAX_DEPTH = 8\nLEARNING_RATE = 0.01\nFOLDS = 5\n\n# data loading\nDEBUG = False\nSAMPLE = 0.2\nSEED = 42","metadata":{"execution":{"iopub.status.busy":"2022-10-17T10:33:15.906470Z","iopub.execute_input":"2022-10-17T10:33:15.907432Z","iopub.status.idle":"2022-10-17T10:33:15.918278Z","shell.execute_reply.started":"2022-10-17T10:33:15.907386Z","shell.execute_reply":"2022-10-17T10:33:15.917029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"execution":{"iopub.status.busy":"2022-10-17T10:33:15.919825Z","iopub.execute_input":"2022-10-17T10:33:15.920432Z","iopub.status.idle":"2022-10-17T10:33:15.934399Z","shell.execute_reply.started":"2022-10-17T10:33:15.920383Z","shell.execute_reply":"2022-10-17T10:33:15.933214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ncol_dtypes = {\n    'game_num': 'int8', 'event_id': 'int8', 'event_time': 'float16',\n    'ball_pos_x': 'float16', 'ball_pos_y': 'float16', 'ball_pos_z': 'float16',\n    'ball_vel_x': 'float16', 'ball_vel_y': 'float16', 'ball_vel_z': 'float16',\n    'p0_pos_x': 'float16', 'p0_pos_y': 'float16', 'p0_pos_z': 'float16',\n    'p0_vel_x': 'float16', 'p0_vel_y': 'float16', 'p0_vel_z': 'float16',\n    'p0_boost': 'float16', 'p1_pos_x': 'float16', 'p1_pos_y': 'float16',\n    'p1_pos_z': 'float16', 'p1_vel_x': 'float16', 'p1_vel_y': 'float16',\n    'p1_vel_z': 'float16', 'p1_boost': 'float16', 'p2_pos_x': 'float16',\n    'p2_pos_y': 'float16', 'p2_pos_z': 'float16', 'p2_vel_x': 'float16',\n    'p2_vel_y': 'float16', 'p2_vel_z': 'float16', 'p2_boost': 'float16',\n    'p3_pos_x': 'float16', 'p3_pos_y': 'float16', 'p3_pos_z': 'float16',\n    'p3_vel_x': 'float16', 'p3_vel_y': 'float16', 'p3_vel_z': 'float16',\n    'p3_boost': 'float16', 'p4_pos_x': 'float16', 'p4_pos_y': 'float16',\n    'p4_pos_z': 'float16', 'p4_vel_x': 'float16', 'p4_vel_y': 'float16',\n    'p4_vel_z': 'float16', 'p4_boost': 'float16', 'p5_pos_x': 'float16',\n    'p5_pos_y': 'float16', 'p5_pos_z': 'float16', 'p5_vel_x': 'float16',\n    'p5_vel_y': 'float16', 'p5_vel_z': 'float16', 'p5_boost': 'float16',\n    'boost0_timer': 'float16', 'boost1_timer': 'float16', 'boost2_timer': 'float16',\n    'boost3_timer': 'float16', 'boost4_timer': 'float16', 'boost5_timer': 'float16',\n    'player_scoring_next': 'O', 'team_scoring_next': 'O', 'team_A_scoring_within_10sec': 'O',\n    'team_B_scoring_within_10sec': 'O'\n}\ncols = list(col_dtypes.keys())\n\npath_to_data = '../input/tabular-playground-series-oct-2022'\ndf = pd.DataFrame({}, columns=cols)\nfor i in range(10):\n    df_tmp = pd.read_csv(f'{path_to_data}/train_{i}.csv', dtype=col_dtypes)\n    if SAMPLE < 1:\n        df_tmp = df_tmp.sample(frac=SAMPLE, random_state=SEED)\n        \n    df = pd.concat([df, df_tmp])\n    del df_tmp\n    gc.collect()\n    if DEBUG:\n        break","metadata":{"execution":{"iopub.status.busy":"2022-10-17T10:33:15.936813Z","iopub.execute_input":"2022-10-17T10:33:15.937156Z","iopub.status.idle":"2022-10-17T10:38:16.015858Z","shell.execute_reply.started":"2022-10-17T10:33:15.937118Z","shell.execute_reply":"2022-10-17T10:38:16.014279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output_cols = ['team_A_scoring_within_10sec', 'team_B_scoring_within_10sec']","metadata":{"execution":{"iopub.status.busy":"2022-10-17T10:38:16.017528Z","iopub.execute_input":"2022-10-17T10:38:16.018612Z","iopub.status.idle":"2022-10-17T10:38:16.024837Z","shell.execute_reply.started":"2022-10-17T10:38:16.018564Z","shell.execute_reply":"2022-10-17T10:38:16.023438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2022-10-17T10:38:16.026547Z","iopub.execute_input":"2022-10-17T10:38:16.028361Z","iopub.status.idle":"2022-10-17T10:38:18.359347Z","shell.execute_reply.started":"2022-10-17T10:38:16.028306Z","shell.execute_reply":"2022-10-17T10:38:18.358146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"_df = df[ (df[\"game_num\"] == 29)]","metadata":{"execution":{"iopub.status.busy":"2022-10-17T11:10:29.855960Z","iopub.execute_input":"2022-10-17T11:10:29.856417Z","iopub.status.idle":"2022-10-17T11:10:30.220945Z","shell.execute_reply.started":"2022-10-17T11:10:29.856378Z","shell.execute_reply":"2022-10-17T11:10:30.219844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tmp_df = _df.isnull().any(axis = 1)\n_df = _df[tmp_df]\n_df","metadata":{"execution":{"iopub.status.busy":"2022-10-17T11:10:30.222771Z","iopub.execute_input":"2022-10-17T11:10:30.223135Z","iopub.status.idle":"2022-10-17T11:10:30.268733Z","shell.execute_reply.started":"2022-10-17T11:10:30.223102Z","shell.execute_reply":"2022-10-17T11:10:30.267674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#_df[\"game_num\"].value_counts()\n_df.columns\n_df.iloc[:,9:]\npos_x = [ x for x in _df.columns if \"pos_x\" in x ]\n\ntemp_df = _df[pos_x + [\"team_A_scoring_within_10sec\", \"team_B_scoring_within_10sec\"]]\nteam_a = _df[['p0_pos_x','p1_pos_x','p2_pos_x']]\nteam_b = _df[['p3_pos_x','p4_pos_x','p5_pos_x']]\nteam_a.isnull().sum(axis = 1)\nteam_b.isnull().sum(axis = 1)\ntemp_df[\"team_a_player_num\"] = team_a.isnull().sum(axis = 1)\ntemp_df[\"team_b_player_num\"] = team_b.isnull().sum(axis = 1)","metadata":{"execution":{"iopub.status.busy":"2022-10-17T11:10:32.341378Z","iopub.execute_input":"2022-10-17T11:10:32.341762Z","iopub.status.idle":"2022-10-17T11:10:32.357943Z","shell.execute_reply.started":"2022-10-17T11:10:32.341730Z","shell.execute_reply":"2022-10-17T11:10:32.356720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp_df","metadata":{"execution":{"iopub.status.busy":"2022-10-17T11:10:57.746205Z","iopub.execute_input":"2022-10-17T11:10:57.746580Z","iopub.status.idle":"2022-10-17T11:10:57.770952Z","shell.execute_reply.started":"2022-10-17T11:10:57.746549Z","shell.execute_reply":"2022-10-17T11:10:57.769777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp_df.groupby(\"team_A_scoring_within_10sec\").describe().T.iloc[25:,:]# [[\"team_b_player_num\",\"team_b_player_num\"]]","metadata":{"execution":{"iopub.status.busy":"2022-10-17T11:11:02.143623Z","iopub.execute_input":"2022-10-17T11:11:02.144058Z","iopub.status.idle":"2022-10-17T11:11:02.213212Z","shell.execute_reply.started":"2022-10-17T11:11:02.144004Z","shell.execute_reply":"2022-10-17T11:11:02.211936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-10-17T11:03:46.001143Z","iopub.execute_input":"2022-10-17T11:03:46.002121Z","iopub.status.idle":"2022-10-17T11:03:46.012877Z","shell.execute_reply.started":"2022-10-17T11:03:46.002069Z","shell.execute_reply":"2022-10-17T11:03:46.011811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-10-17T11:03:08.150025Z","iopub.execute_input":"2022-10-17T11:03:08.150845Z","iopub.status.idle":"2022-10-17T11:03:08.189424Z","shell.execute_reply.started":"2022-10-17T11:03:08.150805Z","shell.execute_reply":"2022-10-17T11:03:08.188275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}