{"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":"markdown","source":"![Alt Text](https://media3.giphy.com/media/nXg2lqVpal6KgSC8Zq/200.gif)\n\n","metadata":{}},{"cell_type":"markdown","source":"# Library import","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"import matplotlib\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport numpy as np\nimport pandas as pd\nimport gc\nfrom tqdm.notebook import trange, tqdm\n\nfrom sklearn.model_selection import KFold, StratifiedKFold, GroupKFold\nfrom lightgbm import LGBMClassifier\nfrom catboost import CatBoostClassifier\nfrom sklearn.ensemble import ExtraTreesClassifier\nfrom xgboost import XGBClassifier\nfrom sklearn.metrics import accuracy_score, roc_auc_score, log_loss\n\n\nfrom mpl_toolkits import mplot3d\nfrom scipy.spatial import Delaunay\n\nfrom IPython.display import Latex\n","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:31.248242Z","iopub.execute_input":"2022-10-22T09:35:31.249188Z","iopub.status.idle":"2022-10-22T09:35:31.255822Z","shell.execute_reply.started":"2022-10-22T09:35:31.249148Z","shell.execute_reply":"2022-10-22T09:35:31.254707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Loading","metadata":{}},{"cell_type":"markdown","source":"Using Dask we can Load in the entire data set. ","metadata":{}},{"cell_type":"markdown","source":"![dask](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAU8AAACWCAMAAABpVfqTAAABNVBMVEX///8QEBEAAADPYDsMDA0FBQcKCgs7Ozu8vLw+Pj9aWloeHh/i4uL19fXRZj+EhITrrG/OWjr29vYlJ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WCoWXk5ror+vEPo3R6aeq/giMm3/4lv/NKmaMSo+cHhzWzBWkWhq2IoiHi9fksYrxuMIp6GCN6OHg4PbwcKsmjyKfnzBPcWKpBM9owU8UUThb1wFslbljf4dPGvAMjDh5rqJSi/oB4RJbhlNZrM6RRwhlVaD0CqV+ieFS6gEevIR5qv///CrVwR3p4dJWcolkoonqtfq3Eq8ScUdp7KtqLwWa2ZtW1ym5FlQ/fSNo4Dy9Z5WSqurrr9UvUq2rr92TdYqIZ+Nv1ddfqzpkm76RzAh/KJPy668XHj71BzMQnIUHVTxuQ2f6gwTog21eVO24HRWfKE9ceiosmqt2Sq3pWeBZKKiBs139mB3Xed6/KNtsW/Un8uCQTHpNvrZJqSXd4u6eSZ8dqoCzI5r9+JT+daBMs0Oq/W/2oPbG/mXLv1k2T61UUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSerP6P/zLG+OXT3HRAAAAAElFTkSuQmCC)","metadata":{}},{"cell_type":"markdown","source":"Copied Load in from [here](https://www.kaggle.com/code/donatoriccio/how-to-load-the-whole-dataset-in-2-lines-of-code?scriptVersionId=108551145&cellId=6)","metadata":{}},{"cell_type":"code","source":"# import dask.dataframe as dd\n# dtypes_dict = {\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': 'int8',\n#     'team_B_scoring_within_10sec': 'int8'\n# }\n\n\n# df = dd.read_csv('../input/tabular-playground-series-oct-2022/train_*.csv', dtype = dtypes_dict)\n# df = df.compute()\n# df = df.iloc[:,:-2].head(1000000)\n# df.shape[0]","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:31.257948Z","iopub.execute_input":"2022-10-22T09:35:31.258395Z","iopub.status.idle":"2022-10-22T09:35:31.279075Z","shell.execute_reply.started":"2022-10-22T09:35:31.258347Z","shell.execute_reply":"2022-10-22T09:35:31.277874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\n","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:31.280812Z","iopub.execute_input":"2022-10-22T09:35:31.281617Z","iopub.status.idle":"2022-10-22T09:35:31.298962Z","shell.execute_reply.started":"2022-10-22T09:35:31.281542Z","shell.execute_reply":"2022-10-22T09:35:31.297778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.read_feather(\"../input/fast-loading-high-compression-with-feather/feather_data/test_compressed.ftr\")","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:31.301615Z","iopub.execute_input":"2022-10-22T09:35:31.302382Z","iopub.status.idle":"2022-10-22T09:35:31.505327Z","shell.execute_reply.started":"2022-10-22T09:35:31.302340Z","shell.execute_reply":"2022-10-22T09:35:31.504109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_feather(\"../input/fast-loading-high-compression-with-feather/feather_data/train_0_compressed.ftr\")","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:31.506751Z","iopub.execute_input":"2022-10-22T09:35:31.507124Z","iopub.status.idle":"2022-10-22T09:35:34.312331Z","shell.execute_reply.started":"2022-10-22T09:35:31.507089Z","shell.execute_reply":"2022-10-22T09:35:34.311176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Delaunay Triangulation ","metadata":{}},{"cell_type":"markdown","source":"<img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/Delaunay_circumcircles_centers.svg/1024px-Delaunay_circumcircles_centers.svg.png\" alt=\"drawing\" width=\"400\"/>\n\n## Definition: \n*In mathematics and computational geometry, a Delaunay triangulation (also known as a Delone triangulation) for a given set P of discrete points in a general position is a triangulation DT(P) such that no point in P is inside the circumcircle of any triangle in DT(P). Delaunay triangulations maximize the minimum of all the angles of the triangles in the triangulation; they tend to avoid sliver triangles. The triangulation is named after Boris Delaunay for his work on this topic from 1934.*\n","metadata":{}},{"cell_type":"code","source":"def Delaunay_tri(x,y,z):\n    '''function which perform Delaunay Triangulations \n    returns point indices and coordinates for triangles forming the triangulation '''\n    points = np.vstack([x, y, z]).T\n    tri = Delaunay(points)\n    return points, tri\n\ndef Delaunay_tri_2D(x,y):\n    points = np.vstack([x, y]).T\n    tri = Delaunay(points)\n    return points, tri\n","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:34.313748Z","iopub.execute_input":"2022-10-22T09:35:34.314456Z","iopub.status.idle":"2022-10-22T09:35:34.320745Z","shell.execute_reply.started":"2022-10-22T09:35:34.314413Z","shell.execute_reply":"2022-10-22T09:35:34.319892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Getting the Coordinates of Each Player and Adding the Static Coordinates of the Goals\nThe coordinates form the goal is taken from the discussion [here](https://www.kaggle.com/competitions/tabular-playground-series-oct-2022/discussion/356718)","metadata":{}},{"cell_type":"markdown","source":"## Defining Helper Functions","metadata":{}},{"cell_type":"code","source":"def plot_tri(ax, points, tri):\n    edges = collect_edges(tri)\n    x = np.array([])\n    y = np.array([])\n    z = np.array([])\n    for (i,j) in edges:\n        x = np.append(x, [points[i, 0], points[j, 0], np.nan])      \n        y = np.append(y, [points[i, 1], points[j, 1], np.nan])      \n        z = np.append(z, [points[i, 2], points[j, 2], np.nan])\n    ax.plot3D(x, y, z, color='g', lw='1')\n\n    for i in range(len(points)): #plot each point + it's index as text above\n        if i == 0:\n            ax.scatter(points[i,0],points[i,1],points[i,2],color='r', s=120)\n            ax.text(points[i,0],points[i,1],points[i,2],  '%s' % 'Ball', size=30, zorder=1)  \n        elif i > 6:\n            ax.scatter(points[i,0],points[i,1],points[i,2],color='yellow', s=120)\n            ax.text(points[i,0],points[i,1],points[i,2],  '%s' % 'Goal', size=30, zorder=1)  \n        else: \n            ax.scatter(points[i,0],points[i,1],points[i,2],color='b', s=120)\n            ax.text(points[i,0],points[i,1],points[i,2],  '%s' % 'Player ' + (str(i)), size=30, zorder=1)\n        \n\ndef collect_edges(tri):\n    edges = set()\n\n    def sorted_tuple(a,b):\n        return (a,b) if a < b else (b,a)\n    # Add edges of tetrahedron (sorted so we don't add an edge twice, even if it comes in reverse order).\n    for (i0, i1, i2, i3) in tri.simplices:\n        edges.add(sorted_tuple(i0,i1))\n        edges.add(sorted_tuple(i0,i2))\n        edges.add(sorted_tuple(i0,i3))\n        edges.add(sorted_tuple(i1,i2))\n        edges.add(sorted_tuple(i1,i3))\n        edges.add(sorted_tuple(i2,i3))\n    return edges","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:34.322588Z","iopub.execute_input":"2022-10-22T09:35:34.322967Z","iopub.status.idle":"2022-10-22T09:35:34.340039Z","shell.execute_reply.started":"2022-10-22T09:35:34.322903Z","shell.execute_reply":"2022-10-22T09:35:34.338943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# idx corresponding to the row of the dataframe, for now lets look at the first row\ndef get_coordinates(idx=0, cols=df.columns):\n    x_cols = [col for col in cols if 'pos_x' in col]\n    y_cols = [col for col in cols if 'pos_y' in col]\n    z_cols = [col for col in cols if 'pos_z' in col]\n    x = df[x_cols].loc[idx].to_list()\n    y = df[y_cols].loc[idx].to_list()\n    z = df[z_cols].loc[idx].to_list()\n    goal_1 = np.array([0, -100, 0])\n    goal_2 = np.array([0, 100, 0])\n    x.extend([goal_1[0], goal_2[0]])\n    y.extend([goal_1[1], goal_2[1]])\n    z.extend([goal_1[2], goal_2[2]])\n    return x,y,z","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:34.341786Z","iopub.execute_input":"2022-10-22T09:35:34.343317Z","iopub.status.idle":"2022-10-22T09:35:34.358224Z","shell.execute_reply.started":"2022-10-22T09:35:34.343263Z","shell.execute_reply":"2022-10-22T09:35:34.357060Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x,y,z = get_coordinates(idx=10, cols=df.columns)\npoints, tri = Delaunay_tri(x,y,z)\nfig = plt.figure(figsize=(20,17))\nax = plt.axes(projection='3d')\nplot_tri(ax, points, tri)\n","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:34.362732Z","iopub.execute_input":"2022-10-22T09:35:34.363167Z","iopub.status.idle":"2022-10-22T09:35:35.037630Z","shell.execute_reply.started":"2022-10-22T09:35:34.363128Z","shell.execute_reply":"2022-10-22T09:35:35.036382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Some Example Metrics of the Delaunay Graph","metadata":{}},{"cell_type":"code","source":"print('Number of Triangles {len(tri.simplices)} =', len(tri.simplices))\nprint('Hyperplane distance to goal 1 =', sum(tri.plane_distance(points[-1])))\nprint('Hyperplane distance to goal 2 =', sum(tri.plane_distance(points[-2])))\nprint('Hyperplane distance to the ball =', sum(tri.plane_distance(points[0])))","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:35.039344Z","iopub.execute_input":"2022-10-22T09:35:35.040355Z","iopub.status.idle":"2022-10-22T09:35:35.048253Z","shell.execute_reply.started":"2022-10-22T09:35:35.040293Z","shell.execute_reply":"2022-10-22T09:35:35.047153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 2D case","metadata":{}},{"cell_type":"code","source":"import networkx as nx\nfrom matplotlib.widgets import Slider\n\ni = 100\n\nx,y,_ = get_coordinates(idx=i)\npoint, tri = Delaunay_tri_2D(x,y)\nG = nx.Graph()\nfor path in tri.simplices:\n    nx.add_path(G, path)\n    \nnx.draw(G, with_labels=True, node_size=500, node_color='lightgreen')","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:35.049420Z","iopub.execute_input":"2022-10-22T09:35:35.050432Z","iopub.status.idle":"2022-10-22T09:35:35.300099Z","shell.execute_reply.started":"2022-10-22T09:35:35.050378Z","shell.execute_reply":"2022-10-22T09:35:35.299139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Number of noder = Order of the graph\nG.order()","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:35.301307Z","iopub.execute_input":"2022-10-22T09:35:35.302139Z","iopub.status.idle":"2022-10-22T09:35:35.308936Z","shell.execute_reply.started":"2022-10-22T09:35:35.302084Z","shell.execute_reply":"2022-10-22T09:35:35.308052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Density of the Graph","metadata":{}},{"cell_type":"code","source":"# Density of the graph = Graph density represents the ratio between the edges present in a graph and the maximum number of edges that the graph can contain\nfrom networkx.classes.function import density\ndensity(G)","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:35.310415Z","iopub.execute_input":"2022-10-22T09:35:35.311227Z","iopub.status.idle":"2022-10-22T09:35:35.325457Z","shell.execute_reply.started":"2022-10-22T09:35:35.311190Z","shell.execute_reply":"2022-10-22T09:35:35.324341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from networkx.classes.function import degree\ndegree(G, nbunch=None, weight=None)","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:35.327056Z","iopub.execute_input":"2022-10-22T09:35:35.327424Z","iopub.status.idle":"2022-10-22T09:35:35.339687Z","shell.execute_reply.started":"2022-10-22T09:35:35.327392Z","shell.execute_reply":"2022-10-22T09:35:35.338175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Degree Histogram","metadata":{}},{"cell_type":"code","source":"from networkx.classes.function import degree_histogram\ndegree_histogram(G)","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:35.341614Z","iopub.execute_input":"2022-10-22T09:35:35.342006Z","iopub.status.idle":"2022-10-22T09:35:35.354103Z","shell.execute_reply.started":"2022-10-22T09:35:35.341970Z","shell.execute_reply":"2022-10-22T09:35:35.352764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Neigbors of the nodes","metadata":{"execution":{"iopub.status.busy":"2022-10-20T08:22:43.328761Z","iopub.execute_input":"2022-10-20T08:22:43.329154Z","iopub.status.idle":"2022-10-20T08:22:43.335451Z","shell.execute_reply.started":"2022-10-20T08:22:43.329120Z","shell.execute_reply":"2022-10-20T08:22:43.334173Z"}}},{"cell_type":"code","source":"from networkx.classes.function import neighbors\nfor node in G.nodes():\n    print(node, list(G.neighbors(node)))\n","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:35.355412Z","iopub.execute_input":"2022-10-22T09:35:35.355955Z","iopub.status.idle":"2022-10-22T09:35:35.366518Z","shell.execute_reply.started":"2022-10-22T09:35:35.355895Z","shell.execute_reply":"2022-10-22T09:35:35.365237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Adjacency Matrix of The Undirected/ Unweighted Graph","metadata":{}},{"cell_type":"code","source":"# Get the adjacnency Matrix with sorted nodes and cast to numpy array\nA = nx.to_numpy_array(G, nodelist=sorted(G.nodes()))\nA","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:35.368578Z","iopub.execute_input":"2022-10-22T09:35:35.368969Z","iopub.status.idle":"2022-10-22T09:35:35.382602Z","shell.execute_reply.started":"2022-10-22T09:35:35.368927Z","shell.execute_reply":"2022-10-22T09:35:35.381707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Another Matrix Representation which is used often in CNN is the Laplacian Matrix\n","metadata":{}},{"cell_type":"markdown","source":"# Laplacian Matrix","metadata":{"execution":{"iopub.status.busy":"2022-10-20T09:19:28.788202Z","iopub.execute_input":"2022-10-20T09:19:28.788594Z","iopub.status.idle":"2022-10-20T09:19:28.793118Z","shell.execute_reply.started":"2022-10-20T09:19:28.788562Z","shell.execute_reply":"2022-10-20T09:19:28.791984Z"}}},{"cell_type":"markdown","source":"The graph Laplacian is the matrix $\\large L = D - A$, <br>where A is the adjacency matrix and D is the diagonal matrix of node degrees.<br>\nIn most applications it is further sensible to normalize it with $\\large N = D^{1/2} L D^{-1/2}$","metadata":{}},{"cell_type":"code","source":"L = nx.normalized_laplacian_matrix(G,nodelist=sorted(G.nodes()))\nL = np.array(L.todense())\nL","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:35.383867Z","iopub.execute_input":"2022-10-22T09:35:35.384755Z","iopub.status.idle":"2022-10-22T09:35:35.404620Z","shell.execute_reply.started":"2022-10-22T09:35:35.384717Z","shell.execute_reply":"2022-10-22T09:35:35.403529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.manifold import spectral_embedding\ny = spectral_embedding(adjacency=A, \n                                n_components=1, \n                                norm_laplacian=False, \n                                drop_first=True,\n                                eigen_solver='lobpcg')\n\n","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:35.406114Z","iopub.execute_input":"2022-10-22T09:35:35.406706Z","iopub.status.idle":"2022-10-22T09:35:35.415250Z","shell.execute_reply.started":"2022-10-22T09:35:35.406669Z","shell.execute_reply":"2022-10-22T09:35:35.413656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:35.417162Z","iopub.execute_input":"2022-10-22T09:35:35.417660Z","iopub.status.idle":"2022-10-22T09:35:35.428748Z","shell.execute_reply.started":"2022-10-22T09:35:35.417613Z","shell.execute_reply":"2022-10-22T09:35:35.427421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"This Matrix representing a specific graph of player and ball positions can now be used to train our model.","metadata":{}},{"cell_type":"markdown","source":"# Simple Approach: Flattening the Laplacian Matrix + ONLY 2D Positions of the players","metadata":{}},{"cell_type":"code","source":"df = df.dropna()\ny_b = df['team_B_scoring_within_10sec']\ny_a = df['team_A_scoring_within_10sec']\ndf_train = df.copy()","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:35.430315Z","iopub.execute_input":"2022-10-22T09:35:35.430731Z","iopub.status.idle":"2022-10-22T09:35:37.083031Z","shell.execute_reply.started":"2022-10-22T09:35:35.430631Z","shell.execute_reply":"2022-10-22T09:35:37.082014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:37.084624Z","iopub.execute_input":"2022-10-22T09:35:37.085203Z","iopub.status.idle":"2022-10-22T09:35:37.172259Z","shell.execute_reply.started":"2022-10-22T09:35:37.085152Z","shell.execute_reply":"2022-10-22T09:35:37.171264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(df_train.columns)\n# Defining all columns which we willd drop for now!\nto_drop = ['game_num','event_id', 'event_time', 'player_scoring_next', 'team_scoring_next', 'team_B_scoring_within_10sec','team_A_scoring_within_10sec']\nz_list =  [i for i in df_train.columns if '_z' in i]\nvels = [i for i in df_train.columns if 'vel' in i]\nboost  = [i for i in df_train.columns if 'boost' in i]\nall_drop = to_drop+vels+boost+z_list\ndf_train = df_train.drop(all_drop, axis = 1)\n","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:37.177238Z","iopub.execute_input":"2022-10-22T09:35:37.177672Z","iopub.status.idle":"2022-10-22T09:35:37.270638Z","shell.execute_reply.started":"2022-10-22T09:35:37.177631Z","shell.execute_reply":"2022-10-22T09:35:37.269266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"I Have already created graphs for train_sample_a and test data. Else the code below will create graphs from the positions","metadata":{}},{"cell_type":"code","source":"# import networkx as nx\n\n# x_cols = [col for col in df_train.columns if 'pos_x' in col]\n# y_cols = [col for col in df_train.columns if 'pos_y' in col]\n# goal_1 = np.array([0, -100, 0])\n# goal_2 = np.array([0, 100, 0])\n\n# L_train_list = []\n# for i, rows in tqdm(df_train.iterrows()):\n#     if int(i) % 10000 == 0:\n#         print(i)\n#     x = rows[x_cols].to_list()\n#     y = rows[y_cols].to_list()\n#     x.extend([goal_1[0], goal_2[0]])\n#     y.extend([goal_1[1], goal_2[1]])\n#     points, tri = Delaunay_tri_2D(x,y)\n#     G = nx.Graph()\n#     for path in tri.simplices:\n#         nx.add_path(G, path)\n#     A = nx.to_numpy_array(G, nodelist=sorted(G.nodes()))\n#     y = spectral_embedding(adjacency=A, \n#                                 n_components=1, \n#                                 norm_laplacian=False, \n#                                 drop_first=True,\n#                                 eigen_solver='lobpcg').flatten()\n#     L_train_list.append(pd.DataFrame((y.reshape(-1, len(y))), index=[str(i)]))\n# L_train = pd.concat([i.iloc[:,1:] for i in L_train_list])   \n# L_train['y_a'] = list(y_a)\n# L_train['y_b'] = list(y_b)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-10-22T09:35:37.272199Z","iopub.execute_input":"2022-10-22T09:35:37.272674Z","iopub.status.idle":"2022-10-22T09:35:37.279180Z","shell.execute_reply.started":"2022-10-22T09:35:37.272627Z","shell.execute_reply":"2022-10-22T09:35:37.277969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ###### CONVERTING THE TEST SET TO A GRAPH DATA ################\n# X_test = pd.read_csv('../input/tabular-playground-series-oct-2022/test.csv')\n# df_test = X_test.drop('id', axis = 1).fillna(0)\n# x_cols = [col for col in df_test.columns if 'pos_x' in col]\n# y_cols = [col for col in df_test.columns if 'pos_y' in col]\n# goal_1 = np.array([0, -100, 0])\n# goal_2 = np.array([0, 100, 0])\n\n# L_test_list = []\n# for i, rows in tqdm(df_test.iterrows()):\n#     if int(i) % 5000 == 0:\n#         print(i)\n#     x = rows[x_cols].to_list()\n#     y = rows[y_cols].to_list()\n#     x.extend([goal_1[0], goal_2[0]])\n#     y.extend([goal_1[1], goal_2[1]])\n#     points, tri = Delaunay_tri_2D(x,y)\n#     G = nx.Graph()\n#     for path in tri.simplices:\n#         nx.add_path(G, path)\n#     A = nx.to_numpy_array(G, nodelist=sorted(G.nodes()))\n#     y = spectral_embedding(adjacency=A, \n#                                 n_components=1, \n#                                 norm_laplacian=False, \n#                                 drop_first=True,\n#                                 eigen_solver='lobpcg').flatten()\n#     L_test_list.append(pd.DataFrame((y.reshape(-1, len(y))), index=[str(i)]))\n# L_test = pd.concat([i.iloc[:,1:] for i in L_test_list])","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-10-22T09:35:37.280695Z","iopub.execute_input":"2022-10-22T09:35:37.281124Z","iopub.status.idle":"2022-10-22T09:35:37.296887Z","shell.execute_reply.started":"2022-10-22T09:35:37.281087Z","shell.execute_reply":"2022-10-22T09:35:37.295717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# L_test.columns = L_test.columns.astype(str)\n# L_test.reset_index().to_feather('spectral_test_data.ftr')\n# L_test.reset_index().to_csv('spectral_test_data.csv')\n\n# L_train.columns = L_train.columns.astype(str)\n# L_train.reset_index().to_csv('spectral_train_data_a.csv')\n# L_train.reset_index().to_feather('spectral_train_data_b.ftr')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-10-22T09:35:37.298775Z","iopub.execute_input":"2022-10-22T09:35:37.299240Z","iopub.status.idle":"2022-10-22T09:35:37.317034Z","shell.execute_reply.started":"2022-10-22T09:35:37.299192Z","shell.execute_reply":"2022-10-22T09:35:37.315678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_b","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:35:37.318654Z","iopub.execute_input":"2022-10-22T09:35:37.319255Z","iopub.status.idle":"2022-10-22T09:35:37.334246Z","shell.execute_reply.started":"2022-10-22T09:35:37.319117Z","shell.execute_reply":"2022-10-22T09:35:37.333011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"because of the process still being very slow I preprocessed the test data into a graph.","metadata":{}},{"cell_type":"code","source":"L_test = pd.read_feather('../input/spectral-data-rl/spectral_test_data.ftr')\nL_train = pd.read_feather('../input/spectral-data-rl/spectral_train_data_a.ftr')","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:37:09.859959Z","iopub.execute_input":"2022-10-22T09:37:09.860401Z","iopub.status.idle":"2022-10-22T09:37:10.062128Z","shell.execute_reply.started":"2022-10-22T09:37:09.860362Z","shell.execute_reply":"2022-10-22T09:37:10.060858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"L_train.head(3), y_a.head(3), y_a.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:37:11.258352Z","iopub.execute_input":"2022-10-22T09:37:11.258791Z","iopub.status.idle":"2022-10-22T09:37:11.273506Z","shell.execute_reply.started":"2022-10-22T09:37:11.258751Z","shell.execute_reply":"2022-10-22T09:37:11.272397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Some additional feature engineering","metadata":{}},{"cell_type":"markdown","source":"As for now we have only considered the x and y positions of the players and the ball. Lets include some other features.\nLets look at the veloctiy features of the dataframe","metadata":{}},{"cell_type":"code","source":"df[vels].head()","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:37:14.106154Z","iopub.execute_input":"2022-10-22T09:37:14.106606Z","iopub.status.idle":"2022-10-22T09:37:14.272971Z","shell.execute_reply.started":"2022-10-22T09:37:14.106564Z","shell.execute_reply":"2022-10-22T09:37:14.271490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:37:15.690226Z","iopub.execute_input":"2022-10-22T09:37:15.691094Z","iopub.status.idle":"2022-10-22T09:37:15.719233Z","shell.execute_reply.started":"2022-10-22T09:37:15.691039Z","shell.execute_reply":"2022-10-22T09:37:15.717693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def new_feat(df=df):\n    df_vels = df[vels]\n    drop_timer = [i for i in df[boost].columns if 'timer' in i]\n    boost_df = df[boost].drop(columns=drop_timer).reset_index()\n    z_df = df[z_list].reset_index()\n    v_dicts = {'ball_v' : df_vels.iloc[:, 0:3].values,\n               'p_0_v' : df_vels.iloc[:,3:6].values,\n               'p_1_v' : df_vels.iloc[:,6:9].values,\n               'p_2_v' : df_vels.iloc[:,9:12].values,\n               'p_3_v' : df_vels.iloc[:,12:15].values,\n               'p_4_v' : df_vels.iloc[:,15:18].values,\n               'p_5_v' : df_vels.iloc[:,18:21].values}\n    #     v_abs = pd.DataFrame({key: np.linalg.norm(value, axis=1) for key, value in v_dicts.items()})\n    # Absolute values of velocity\n    v_abs_all = pd.DataFrame({'ball_vel' : np.linalg.norm(v_dicts['ball_v'], axis=1),\n                              'player_vel' : sum(np.linalg.norm(value, axis=1) for _, value in v_dicts.items())})\n    # Correlation between each player and the ball\n    v_corr_all = pd.DataFrame({'team_ball_corr': sum(np.einsum('ij,ij->i', v_dicts['ball_v'], value) for _, value in v_dicts.items())})\n    \n    df_new_feat = pd.concat([v_corr_all, v_abs_all, boost_df], axis=1)\n    df_new_feat_norm = df_new_feat/df_new_feat.max()\n    return df_new_feat_norm","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:37:16.939597Z","iopub.execute_input":"2022-10-22T09:37:16.940051Z","iopub.status.idle":"2022-10-22T09:37:16.954482Z","shell.execute_reply.started":"2022-10-22T09:37:16.940012Z","shell.execute_reply":"2022-10-22T09:37:16.953029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Orientation correlation\nAn interesting metric could be the correlation between the orientation of the ball velocity and the players velocity. As Rocket League is a team sport its reasonable to assume that the orientations of each player would need to point in the same direction? ","metadata":{}},{"cell_type":"markdown","source":"# Distributions of the Velocity Correlations and Absolute Velocities","metadata":{}},{"cell_type":"code","source":"df_feats = new_feat(df=df)\nL_train_ = L_train.drop(columns=['ball_vel', 'team_ball_corr', 'player_vel'])\nL_train_new = pd.concat([L_train_, df_feats], axis=1)\nL_train_new = L_train_new.drop(columns=['index'])\nL_train_new.shape","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:39:18.131453Z","iopub.execute_input":"2022-10-22T09:39:18.131934Z","iopub.status.idle":"2022-10-22T09:39:22.109833Z","shell.execute_reply.started":"2022-10-22T09:39:18.131874Z","shell.execute_reply":"2022-10-22T09:39:22.108516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test_feats = new_feat(df=df_test)\nL_test_ = L_test.drop(columns=['ball_vel', 'team_ball_corr', 'player_vel'])\nL_test_new = pd.concat([L_test_, df_test_feats], axis=1)\nL_test_new = L_test_new.drop(columns=['index'])\nL_test_new.shape","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:39:03.840003Z","iopub.execute_input":"2022-10-22T09:39:03.840438Z","iopub.status.idle":"2022-10-22T09:39:05.642248Z","shell.execute_reply.started":"2022-10-22T09:39:03.840401Z","shell.execute_reply":"2022-10-22T09:39:05.640944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data=L_train_new.iloc[:,:9], kde=True)","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:39:28.435686Z","iopub.execute_input":"2022-10-22T09:39:28.436150Z","iopub.status.idle":"2022-10-22T09:40:57.358794Z","shell.execute_reply.started":"2022-10-22T09:39:28.436109Z","shell.execute_reply":"2022-10-22T09:40:57.357218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()\n\nmodelA = LGBMClassifier(objective='binary',\n                      metric='logloss',\n                      importance_type='gain',\n                      random_state=42,\n                      zero_as_missing=True,\n                      learning_rate=0.1,\n                      max_depth=10,\n                      min_child_samples=340,\n                      min_child_weight=1e-05,\n                      n_estimators=100,\n                      num_leaves=130,\n                      reg_alpha=50,\n                      reg_lambda=50)\n\nmodelA.fit(L_train_new, y_a)\ny_a_pred = modelA.predict_proba(L_test_new)\nprint('Model A trained')\n\n# del modelA \n# gc.collect()\n\nmodelB = LGBMClassifier(objective='binary',\n                      metric='logloss',\n                      importance_type='gain',\n                      random_state=42,\n                      zero_as_missing=True,\n                      learning_rate=0.1,\n                      max_depth=10,\n                      min_child_samples=340,\n                      min_child_weight=1e-05,\n                      n_estimators=100,\n                      num_leaves=130,\n                      reg_alpha=50,\n                      reg_lambda=50)\n\nmodelB.fit(L_train_new, y_b)\nprint('Model B trained')\ny_b_pred = modelB.predict_proba(L_test_new)\n\n# del modelB \n# gc.collect()\n\nsubmission = pd.read_csv('../input/tabular-playground-series-oct-2022/sample_submission.csv', usecols = ['id'])\nsubmission['team_A_scoring_within_10sec'] = y_a_pred[:,1]\nsubmission['team_B_scoring_within_10sec'] = y_b_pred[:,1]\nsubmission.to_csv('submission.csv', index = False)","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:40:57.360928Z","iopub.execute_input":"2022-10-22T09:40:57.361313Z","iopub.status.idle":"2022-10-22T09:41:47.490261Z","shell.execute_reply.started":"2022-10-22T09:40:57.361279Z","shell.execute_reply":"2022-10-22T09:41:47.488648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_A = modelA.predict(L_train_new)\ny_pred_B = modelB.predict(L_train_new)\n# view accuracy\nfrom sklearn.metrics import accuracy_score\n\naccuracy_A = accuracy_score(y_pred_A, y_a)\naccuracy_B = accuracy_score(y_pred_B, y_b)\nprint(f'LightGBM Model accuracy scores: {accuracy_A, accuracy_B}')","metadata":{"execution":{"iopub.status.busy":"2022-10-22T09:41:47.492044Z","iopub.execute_input":"2022-10-22T09:41:47.493144Z","iopub.status.idle":"2022-10-22T09:42:02.193383Z","shell.execute_reply.started":"2022-10-22T09:41:47.493083Z","shell.execute_reply":"2022-10-22T09:42:02.192033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Summary","metadata":{}},{"cell_type":"markdown","source":"With this super simplified method of only using the x and y positions of each player to construct a graph + completely ignoring all other parameters + only using train_a samples this method achieves a score of $\\large 0.22114$. Now we need to include the other parameters and more train sample to increase the score, but the approach seems promising!\n","metadata":{}},{"cell_type":"markdown","source":"--------------------------------------------------------------------------------------------------------------------------------------------------------","metadata":{}},{"cell_type":"markdown","source":"# *FUTURE WORK*","metadata":{}},{"cell_type":"markdown","source":"# Using the Graphs as Inputs for a GNN ","metadata":{"execution":{"iopub.status.busy":"2022-10-20T08:45:49.993592Z","iopub.execute_input":"2022-10-20T08:45:49.994009Z","iopub.status.idle":"2022-10-20T08:45:49.998983Z","shell.execute_reply.started":"2022-10-20T08:45:49.993968Z","shell.execute_reply":"2022-10-20T08:45:49.997715Z"}}},{"cell_type":"markdown","source":"### A GNN is is a neural network that can directly be applied to graphs on:\n* node level \n* edge level\n* **graph level**","metadata":{"execution":{"iopub.status.busy":"2022-10-20T08:46:31.897327Z","iopub.execute_input":"2022-10-20T08:46:31.897754Z","iopub.status.idle":"2022-10-20T08:46:31.908347Z","shell.execute_reply.started":"2022-10-20T08:46:31.897718Z","shell.execute_reply":"2022-10-20T08:46:31.906289Z"}}},{"cell_type":"markdown","source":"we are interested in a Graph Classification on graph level: <br>\n### **Given a graph of player and ball positions will the team score within 10s?**","metadata":{}},{"cell_type":"markdown","source":"# Node Embeddings in GNN \n## Principle \n* Nodes have neighbors and connections \n* Neighors of a node and connections to neighbors define the concept of the node <br>","metadata":{}},{"cell_type":"markdown","source":"## Node Embeddings\n* Every node represents its concept as a state ($x$)\n* The node state ($x$) produces the decision about its concepts an an output ($o$)\n* The final state ($x_n$) of the node is called Node Embedding","metadata":{}},{"cell_type":"markdown","source":"## TO BE CONTINUED ","metadata":{}}]}