{"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":"# Predicting Special Team Play Result and Player Recommendation Using Knowledge Graph","metadata":{"editable":false}},{"cell_type":"markdown","source":" \n1.\tIntroduction\n\nAmerican Football is one of America's most popular strategic sports, played by two teams of eleven players on a rectangular field with goalposts at each end. Each team in American football consists of 3 different units: offensive team, defensive team, and special team, which have their respective functions in the game. Unlike offence or defence, special teams are responsible for scoring points and protecting points and field positions. According to Will Hewlett, special teams are one of the most overlooked aspects of football [1]. Although Many people might underestimate the impact of special teams because special team units are only on the field for about 20% of the play in most games, special team play can mean the difference between winning and losing[2]. The performance of a special team alone will not win a football game, but it can make a significant impact on the result, with a difference of more than a goal between the best and worst punt units.\nAs a collective term, Special teams are made up of several similar, but ultimately different, units: punt, punt return, kick-off, kick-off return, field goal/PAT, and field goal/PAT block[3]. Each unit has its specialization and specific strategies to get a score or good field position. In general, there are 4 types of games played by special teams, namely Kick off, Punt, Field Goal and Extra Point. Unlike Field Goal and Extra Point, Kickoff and Punt can change the game direction; besides aiming to secure the field position, this type of game also has its own risks and advantages. For example, if the kicking team do a Kick-off and the return team manages to catch the ball and bring it to the end of the opponent's zone, this will give the opponent a significant advantage. Therefore, selecting the play type result strategy from the type of game will determine the game's outcome. Because of the importance of the special team play type, especially Kick-off and Punt's performances, our goal is to predict the special team play type result to improve the team winning strategy. \nObjectives :\nThe long term goal of our project is to predict the special team play type result (score or not score) to improve the team winning strategy. The objective of our projects such as :\n1.\tTo predict the special team result ( score or not score) based on a related dataset provided by Kaggle.\n2.\tTo compare and evaluate the performance of the selected supervised learning algorithm.\n3.\tTo provide final recommendations to those in need regarding a good strategy in improving the special teams' performance.\n","metadata":{"editable":false}},{"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)\nimport networkx as nx\nimport matplotlib.pyplot as plt # for plot\nfrom matplotlib.pyplot import figure\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":{"editable":false,"execution":{"iopub.status.busy":"2022-01-04T18:00:45.827923Z","iopub.execute_input":"2022-01-04T18:00:45.828842Z","iopub.status.idle":"2022-01-04T18:00:46.163383Z","shell.execute_reply.started":"2022-01-04T18:00:45.828731Z","shell.execute_reply":"2022-01-04T18:00:46.162486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"This notebook is intended to be a study of the NFL Big Data Bowl data, as well as some general engineering and building classification models of interest.\nThe major focus here is feature engineering, which uses four of the NFL's special teams datasets to develop a model that can predict whether a punt or a kickoff will result in a touchdown or not.\nAnother goal of this notebook is to explore more about the relation between players using Knowledge Graph and in the end, will result a recommender system\nSo, this notebook consist of 2 part :\nPart 1: Prediction Model\nPart 2: Knowledge Graph","metadata":{"editable":false}},{"cell_type":"markdown","source":"# **PART I. PREDICTION MODEL**\n\nPredicting Play Type Result ( Score or not Score)","metadata":{}},{"cell_type":"markdown","source":"## LOADING DATASET\nLoad Dataset into dataframe","metadata":{}},{"cell_type":"code","source":"df= pd.read_csv(\"../input/nfl-big-data-bowl-2022/PFFScoutingData.csv\")\ndf2 = pd.read_csv(\"../input/nfl-big-data-bowl-2022/games.csv\")\ndf3 = pd.read_csv(\"../input/nfl-big-data-bowl-2022/players.csv\")\ndf4 = pd.read_csv(\"../input/nfl-big-data-bowl-2022/plays.csv\")\ndf5 = pd.read_csv(\"../input/nfl-big-data-bowl-2022/tracking2018.csv\")\n#df5_2 = pd.read_csv(\"../input/nfl-big-data-bowl-2022/tracking2019.csv\")\n#df5_3 = pd.read_csv(\"../input/nfl-big-data-bowl-2022/tracking2020.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:00:46.165456Z","iopub.execute_input":"2022-01-04T18:00:46.165736Z","iopub.status.idle":"2022-01-04T18:01:24.201279Z","shell.execute_reply.started":"2022-01-04T18:00:46.165699Z","shell.execute_reply":"2022-01-04T18:01:24.200518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## **DATA PREPOCESSING**","metadata":{}},{"cell_type":"code","source":"#making dataframe using only related feature that we want to use\nplays = df4[['gameId','playId','possessionTeam','specialTeamsPlayType','specialTeamsResult','kickerId','returnerId','kickBlockerId','penaltyCodes','penaltyYards','preSnapHomeScore','preSnapVisitorScore','passResult','kickLength','kickReturnYardage','playResult']]\ngames = df2[['gameId','homeTeamAbbr','visitorTeamAbbr']]\nplayers = df3[['nflId','collegeName']]\nscout = df[['gameId','playId','snapDetail','operationTime','hangTime','kickType','kickDirectionIntended','kickDirectionActual','returnDirectionIntended','returnDirectionActual','missedTackler','assistTackler','tackler','kickoffReturnFormation','gunners','puntRushers','specialTeamsSafeties','vises','kickContactType']]\n\n#track2018 = df5[['s','a','dis','nflId','gameId','playId']]\n#track2019 = df5_2[['s','a','dis','nflId','gameId','playId']]\n#track2020 = ddf5_3[['s','a','dis','nflId','gameId','playId','jerseyNumber','team']]\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:01:24.202813Z","iopub.execute_input":"2022-01-04T18:01:24.203281Z","iopub.status.idle":"2022-01-04T18:01:24.229980Z","shell.execute_reply.started":"2022-01-04T18:01:24.203232Z","shell.execute_reply":"2022-01-04T18:01:24.229150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 1. Merge Plays and Scout dataset","metadata":{}},{"cell_type":"code","source":"#merging plays dataset and scout dataset into play_scout\nplay_scout = pd.merge(plays, scout, how='left', on=['playId','gameId'])","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:01:24.232082Z","iopub.execute_input":"2022-01-04T18:01:24.232503Z","iopub.status.idle":"2022-01-04T18:01:24.281103Z","shell.execute_reply.started":"2022-01-04T18:01:24.232469Z","shell.execute_reply":"2022-01-04T18:01:24.280464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#separate multiple user in dataset using explode technique\n\nplay_scout = play_scout.assign(returnerId=play_scout['returnerId'].str.split(';')).explode('returnerId')\nplay_scout = play_scout.assign(penaltyCodes=play_scout['penaltyCodes'].str.split(';')).explode('penaltyCodes')\nplay_scout = play_scout.assign(missedTackler=play_scout['missedTackler'].str.split(';')).explode('missedTackler')\nplay_scout = play_scout.assign(assistTackler=play_scout['assistTackler'].str.split(';')).explode('assistTackler')\nplay_scout = play_scout.assign(gunners=play_scout['gunners'].str.split(';')).explode('gunners')\nplay_scout = play_scout.assign(puntRushers=play_scout['puntRushers'].str.split(';')).explode('puntRushers')\nplay_scout = play_scout.assign(specialTeamsSafeties=play_scout['specialTeamsSafeties'].str.split(';')).explode('specialTeamsSafeties')\nplay_scout = play_scout.assign(vises=play_scout['vises'].str.split(';')).explode('vises')","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:01:24.282426Z","iopub.execute_input":"2022-01-04T18:01:24.282878Z","iopub.status.idle":"2022-01-04T18:01:25.031542Z","shell.execute_reply.started":"2022-01-04T18:01:24.282843Z","shell.execute_reply":"2022-01-04T18:01:25.030649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#add new coulumn 'home team' of returner team into first dataframe by gameId\nplay_scout['homeTeam'] =play_scout.gameId.map(games.set_index('gameId')['homeTeamAbbr'].to_dict())","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:01:25.033071Z","iopub.execute_input":"2022-01-04T18:01:25.033351Z","iopub.status.idle":"2022-01-04T18:01:25.044174Z","shell.execute_reply.started":"2022-01-04T18:01:25.033311Z","shell.execute_reply":"2022-01-04T18:01:25.043406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2. Merge Plays_scout and games dataset","metadata":{}},{"cell_type":"code","source":"#merging dataframe play_scout and games into play_scout\nplay_scout=play_scout.merge(games[['gameId','homeTeamAbbr','visitorTeamAbbr']],how='left',left_on=['gameId','possessionTeam'],right_on=['gameId','homeTeamAbbr']).drop('homeTeamAbbr', axis='columns').fillna(games['homeTeamAbbr'])","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:01:25.045768Z","iopub.execute_input":"2022-01-04T18:01:25.046330Z","iopub.status.idle":"2022-01-04T18:01:25.229371Z","shell.execute_reply.started":"2022-01-04T18:01:25.046292Z","shell.execute_reply":"2022-01-04T18:01:25.228546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#define visitor team and add new coulumn 'visitor team'\nfor i in range(len(play_scout)):\n  if (play_scout.loc[i, 'possessionTeam'] != play_scout.loc[i, 'homeTeam']) :\n        play_scout.loc[i, 'visitorTeamAbbr'] = play_scout.loc[i, 'homeTeam']","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:01:25.230611Z","iopub.execute_input":"2022-01-04T18:01:25.231483Z","iopub.status.idle":"2022-01-04T18:02:11.532138Z","shell.execute_reply.started":"2022-01-04T18:01:25.231443Z","shell.execute_reply":"2022-01-04T18:02:11.531400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#rename visitor team to returner team\nplay_scout = play_scout.rename(columns={\"visitorTeamAbbr\": \"returnerTeam\"})","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:02:11.533638Z","iopub.execute_input":"2022-01-04T18:02:11.533895Z","iopub.status.idle":"2022-01-04T18:02:11.551617Z","shell.execute_reply.started":"2022-01-04T18:02:11.533860Z","shell.execute_reply":"2022-01-04T18:02:11.550906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:02:11.554769Z","iopub.execute_input":"2022-01-04T18:02:11.554973Z","iopub.status.idle":"2022-01-04T18:02:11.586185Z","shell.execute_reply.started":"2022-01-04T18:02:11.554949Z","shell.execute_reply":"2022-01-04T18:02:11.585488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### In this part, I will generate new feature named \"eventScore\", ","metadata":{}},{"cell_type":"code","source":"# calcalute home and visitor current score\nfor x in range(len(play_scout)-1):\n  if play_scout.loc[x, 'preSnapHomeScore'] != play_scout.loc[x+1, 'preSnapHomeScore']:\n    play_scout.loc[x, 'homeCurrentScore'] = (play_scout.loc[x+1, 'preSnapHomeScore']-play_scout.loc[x, 'preSnapHomeScore'])\n  else:\n    play_scout.loc[x, 'homeCurrentScore'] = 0\n  if play_scout.loc[x, 'preSnapVisitorScore'] != play_scout.loc[x+1, 'preSnapVisitorScore']:\n    play_scout.loc[x, 'visitorCurrentScore'] = (play_scout.loc[x+1, 'preSnapVisitorScore']-play_scout.loc[x, 'preSnapVisitorScore'])\n  else:\n    play_scout.loc[x, 'visitorCurrentScore'] = 0","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:02:11.587529Z","iopub.execute_input":"2022-01-04T18:02:11.587816Z","iopub.status.idle":"2022-01-04T18:03:28.930473Z","shell.execute_reply.started":"2022-01-04T18:02:11.587780Z","shell.execute_reply":"2022-01-04T18:03:28.929743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#calculate event score\nplay_scout['eventScore']= play_scout['homeCurrentScore']+play_scout['visitorCurrentScore']","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:03:28.931769Z","iopub.execute_input":"2022-01-04T18:03:28.932002Z","iopub.status.idle":"2022-01-04T18:03:28.939036Z","shell.execute_reply.started":"2022-01-04T18:03:28.931970Z","shell.execute_reply":"2022-01-04T18:03:28.938308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#normalized home and visitor score\nfor x in range(len(play_scout)-1):\n  if play_scout.loc[x, 'homeCurrentScore']<0: \n    play_scout.loc[x, 'homeCurrentScore']=0\n  if play_scout.loc[x, 'visitorCurrentScore']<0: \n    play_scout.loc[x, 'visitorCurrentScore']=0","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:03:28.940113Z","iopub.execute_input":"2022-01-04T18:03:28.940519Z","iopub.status.idle":"2022-01-04T18:03:31.606534Z","shell.execute_reply.started":"2022-01-04T18:03:28.940482Z","shell.execute_reply":"2022-01-04T18:03:31.605802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#define score or not score\nfor x in range(len(play_scout)-1):\n  if play_scout.loc[x, 'eventScore'] > 0: #not score\n    play_scout.loc[x, 'eventScore'] = 1\n  else:\n    play_scout.loc[x, 'eventScore'] = 0 #not score","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:03:31.607610Z","iopub.execute_input":"2022-01-04T18:03:31.607846Z","iopub.status.idle":"2022-01-04T18:04:08.913014Z","shell.execute_reply.started":"2022-01-04T18:03:31.607813Z","shell.execute_reply":"2022-01-04T18:04:08.911532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 3. Merge Plays_scout and players dataset","metadata":{}},{"cell_type":"code","source":"#merging play_scout dataframa and players dataframe into play_scout for define kicker college\nplay_scout = pd.merge(play_scout, players, how='left', left_on=['kickerId'],right_on=['nflId'])","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:04:08.915121Z","iopub.execute_input":"2022-01-04T18:04:08.915793Z","iopub.status.idle":"2022-01-04T18:04:09.141889Z","shell.execute_reply.started":"2022-01-04T18:04:08.915752Z","shell.execute_reply":"2022-01-04T18:04:09.140942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del play_scout['nflId']","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:04:09.146341Z","iopub.execute_input":"2022-01-04T18:04:09.146972Z","iopub.status.idle":"2022-01-04T18:04:09.154652Z","shell.execute_reply.started":"2022-01-04T18:04:09.146933Z","shell.execute_reply":"2022-01-04T18:04:09.153893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#rename\nplay_scout = play_scout.rename(columns={\"collegeName\": \"kickerCollege\"})","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:04:09.159145Z","iopub.execute_input":"2022-01-04T18:04:09.161718Z","iopub.status.idle":"2022-01-04T18:04:09.212812Z","shell.execute_reply.started":"2022-01-04T18:04:09.161679Z","shell.execute_reply":"2022-01-04T18:04:09.211962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#change datatype for returner id\n#play_scout['returnerId'] = play_scout['returnerId'].astype(np.float).astype(\"Int64\")\nplay_scout['returnerId'] = play_scout['returnerId'].astype(np.float)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:04:09.217117Z","iopub.execute_input":"2022-01-04T18:04:09.219192Z","iopub.status.idle":"2022-01-04T18:04:09.252218Z","shell.execute_reply.started":"2022-01-04T18:04:09.217476Z","shell.execute_reply":"2022-01-04T18:04:09.251425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#merging play_scout dataframa and players dataframe into play_scout for define returner college\nplay_scout = pd.merge(play_scout, players, how='left', left_on=['returnerId'],right_on=['nflId'])","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:04:09.256102Z","iopub.execute_input":"2022-01-04T18:04:09.258107Z","iopub.status.idle":"2022-01-04T18:04:09.478399Z","shell.execute_reply.started":"2022-01-04T18:04:09.258065Z","shell.execute_reply":"2022-01-04T18:04:09.477623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del play_scout['nflId']","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:04:09.479968Z","iopub.execute_input":"2022-01-04T18:04:09.480230Z","iopub.status.idle":"2022-01-04T18:04:09.488723Z","shell.execute_reply.started":"2022-01-04T18:04:09.480196Z","shell.execute_reply":"2022-01-04T18:04:09.487906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout = play_scout.rename(columns={\"collegeName\": \"returnerCollege\"})","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:04:09.492281Z","iopub.execute_input":"2022-01-04T18:04:09.493078Z","iopub.status.idle":"2022-01-04T18:04:09.535153Z","shell.execute_reply.started":"2022-01-04T18:04:09.493046Z","shell.execute_reply":"2022-01-04T18:04:09.534364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:04:09.536728Z","iopub.execute_input":"2022-01-04T18:04:09.537180Z","iopub.status.idle":"2022-01-04T18:04:09.542957Z","shell.execute_reply.started":"2022-01-04T18:04:09.537143Z","shell.execute_reply":"2022-01-04T18:04:09.542095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout.head(1)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:04:09.544516Z","iopub.execute_input":"2022-01-04T18:04:09.545165Z","iopub.status.idle":"2022-01-04T18:04:09.572110Z","shell.execute_reply.started":"2022-01-04T18:04:09.545128Z","shell.execute_reply":"2022-01-04T18:04:09.571441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:04:09.573471Z","iopub.execute_input":"2022-01-04T18:04:09.573875Z","iopub.status.idle":"2022-01-04T18:04:09.583759Z","shell.execute_reply.started":"2022-01-04T18:04:09.573840Z","shell.execute_reply":"2022-01-04T18:04:09.582885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#define kick and return accuracy\nfor x in range(len(play_scout)-1):\n  if play_scout.loc[x, 'kickDirectionIntended'] == play_scout.loc[x, 'kickDirectionActual']:\n    play_scout.loc[x, 'kickAccuracy'] = 1\n  else:\n    play_scout.loc[x, 'kickAccuracy'] = 0\n  if play_scout.loc[x, 'returnDirectionIntended'] == play_scout.loc[x, 'returnDirectionActual']:\n    play_scout.loc[x, 'returnAccuracy'] = 1\n  else:\n    play_scout.loc[x, 'returnAccuracy']  = 0","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:04:09.585330Z","iopub.execute_input":"2022-01-04T18:04:09.585737Z","iopub.status.idle":"2022-01-04T18:05:31.650710Z","shell.execute_reply.started":"2022-01-04T18:04:09.585685Z","shell.execute_reply":"2022-01-04T18:05:31.649948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 4. Merge track and play_scout\n#### Preparation","metadata":{}},{"cell_type":"code","source":"#laoding data track\ntrack = df5[['gameId','playId','nflId','jerseyNumber','team']]","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:05:31.651850Z","iopub.execute_input":"2022-01-04T18:05:31.652247Z","iopub.status.idle":"2022-01-04T18:05:31.860243Z","shell.execute_reply.started":"2022-01-04T18:05:31.652211Z","shell.execute_reply":"2022-01-04T18:05:31.859518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"track.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:05:31.861446Z","iopub.execute_input":"2022-01-04T18:05:31.862207Z","iopub.status.idle":"2022-01-04T18:05:31.868471Z","shell.execute_reply.started":"2022-01-04T18:05:31.862163Z","shell.execute_reply":"2022-01-04T18:05:31.867234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"track.dropna()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:05:31.876073Z","iopub.execute_input":"2022-01-04T18:05:31.876281Z","iopub.status.idle":"2022-01-04T18:05:33.685231Z","shell.execute_reply.started":"2022-01-04T18:05:31.876258Z","shell.execute_reply":"2022-01-04T18:05:33.684476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"track = track.drop_duplicates()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:05:33.686470Z","iopub.execute_input":"2022-01-04T18:05:33.686728Z","iopub.status.idle":"2022-01-04T18:05:35.689053Z","shell.execute_reply.started":"2022-01-04T18:05:33.686694Z","shell.execute_reply":"2022-01-04T18:05:35.688273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"track = track.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:05:35.690328Z","iopub.execute_input":"2022-01-04T18:05:35.690575Z","iopub.status.idle":"2022-01-04T18:05:35.697843Z","shell.execute_reply.started":"2022-01-04T18:05:35.690543Z","shell.execute_reply":"2022-01-04T18:05:35.696991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"track.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:05:35.699056Z","iopub.execute_input":"2022-01-04T18:05:35.699825Z","iopub.status.idle":"2022-01-04T18:05:35.713399Z","shell.execute_reply.started":"2022-01-04T18:05:35.699786Z","shell.execute_reply":"2022-01-04T18:05:35.712654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#add new coulumn \"hometeam\"\ntrack['homeTeam'] =track.gameId.map(games.set_index('gameId')['homeTeamAbbr'].to_dict())","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:05:35.714764Z","iopub.execute_input":"2022-01-04T18:05:35.715221Z","iopub.status.idle":"2022-01-04T18:05:35.727188Z","shell.execute_reply.started":"2022-01-04T18:05:35.715180Z","shell.execute_reply":"2022-01-04T18:05:35.726358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#add new coulumn \"awayteam\"\ntrack['awayTeam'] =track.gameId.map(games.set_index('gameId')['visitorTeamAbbr'].to_dict())","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:05:35.728740Z","iopub.execute_input":"2022-01-04T18:05:35.729413Z","iopub.status.idle":"2022-01-04T18:05:35.741635Z","shell.execute_reply.started":"2022-01-04T18:05:35.729239Z","shell.execute_reply":"2022-01-04T18:05:35.740892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#define team name for each player based on home team and visitor team\nfor x in range(len(track)-1):\n  if track.loc[x, 'team'] == 'home':\n    track.loc[x, 'teamName'] = track.loc[x, 'homeTeam']\n  else:\n    track.loc[x, 'teamName'] = track.loc[x, 'awayTeam']","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:05:35.742913Z","iopub.execute_input":"2022-01-04T18:05:35.743200Z","iopub.status.idle":"2022-01-04T18:10:15.266363Z","shell.execute_reply.started":"2022-01-04T18:05:35.743164Z","shell.execute_reply":"2022-01-04T18:10:15.265639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del track['team']","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.267727Z","iopub.execute_input":"2022-01-04T18:10:15.267962Z","iopub.status.idle":"2022-01-04T18:10:15.272483Z","shell.execute_reply.started":"2022-01-04T18:10:15.267930Z","shell.execute_reply":"2022-01-04T18:10:15.271831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del track['homeTeam']\ndel track['awayTeam']","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.273802Z","iopub.execute_input":"2022-01-04T18:10:15.274252Z","iopub.status.idle":"2022-01-04T18:10:15.286092Z","shell.execute_reply.started":"2022-01-04T18:10:15.274214Z","shell.execute_reply":"2022-01-04T18:10:15.285362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.288975Z","iopub.execute_input":"2022-01-04T18:10:15.289777Z","iopub.status.idle":"2022-01-04T18:10:15.321976Z","shell.execute_reply.started":"2022-01-04T18:10:15.289695Z","shell.execute_reply":"2022-01-04T18:10:15.321291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# split data from  missed Tackler to gather Jersey number and Team Name\nplay_scout['missedTackler'] = play_scout['missedTackler'].str.replace(\" \",\"\")\nplay_scout['jersyMT']=play_scout['missedTackler'].str[3:]\nplay_scout['missedTackler'] = play_scout['missedTackler'].str[:3]\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.323213Z","iopub.execute_input":"2022-01-04T18:10:15.323697Z","iopub.status.idle":"2022-01-04T18:10:15.370250Z","shell.execute_reply.started":"2022-01-04T18:10:15.323660Z","shell.execute_reply":"2022-01-04T18:10:15.369651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# split data from  Assist Tackler to gather Jersey number and Team Name\nplay_scout['assistTackler'] = play_scout['assistTackler'].str.replace(\" \",\"\")\nplay_scout['jersyAT']=play_scout['assistTackler'].str[3:]\nplay_scout['assistTackler'] = play_scout['assistTackler'].str[:3]","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.371441Z","iopub.execute_input":"2022-01-04T18:10:15.371687Z","iopub.status.idle":"2022-01-04T18:10:15.412857Z","shell.execute_reply.started":"2022-01-04T18:10:15.371655Z","shell.execute_reply":"2022-01-04T18:10:15.412247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# split data from  Tackler to gather Jersey number and Team Name\nplay_scout['tackler'] = play_scout['tackler'].str.replace(\" \",\"\")\nplay_scout['jersyT']=play_scout['tackler'].str[3:]\nplay_scout['tackler'] = play_scout['tackler'].str[:3]\n\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.414036Z","iopub.execute_input":"2022-01-04T18:10:15.414464Z","iopub.status.idle":"2022-01-04T18:10:15.476886Z","shell.execute_reply.started":"2022-01-04T18:10:15.414431Z","shell.execute_reply":"2022-01-04T18:10:15.476268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# split data from  Gunners to gather Jersey number and Team Name\nplay_scout['gunners'] = play_scout['gunners'].str.replace(\" \",\"\")\nplay_scout['jersyG']=play_scout['gunners'].str[3:]\nplay_scout['gunners'] = play_scout['gunners'].str[:3]\n\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.478135Z","iopub.execute_input":"2022-01-04T18:10:15.478378Z","iopub.status.idle":"2022-01-04T18:10:15.574072Z","shell.execute_reply.started":"2022-01-04T18:10:15.478345Z","shell.execute_reply":"2022-01-04T18:10:15.573417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# split data from  puntRushers to gather Jersey number and Team Name\nplay_scout['puntRushers'] = play_scout['puntRushers'].str.replace(\" \",\"\")\nplay_scout['jersyPR']=play_scout['puntRushers'].str[3:]\nplay_scout['puntRushers'] = play_scout['puntRushers'].str[:3]","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.575296Z","iopub.execute_input":"2022-01-04T18:10:15.575526Z","iopub.status.idle":"2022-01-04T18:10:15.652199Z","shell.execute_reply.started":"2022-01-04T18:10:15.575494Z","shell.execute_reply":"2022-01-04T18:10:15.651566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# split data from  specialTeamsSafeties to gather Jersey number and Team Name\nplay_scout['specialTeamsSafeties'] = play_scout['specialTeamsSafeties'].str.replace(\" \",\"\")\nplay_scout['jersySTS']=play_scout['specialTeamsSafeties'].str[3:]\nplay_scout['specialTeamsSafeties'] = play_scout['specialTeamsSafeties'].str[:3]","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.653239Z","iopub.execute_input":"2022-01-04T18:10:15.653507Z","iopub.status.idle":"2022-01-04T18:10:15.739679Z","shell.execute_reply.started":"2022-01-04T18:10:15.653472Z","shell.execute_reply":"2022-01-04T18:10:15.739037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# split data from  vises to gather Jersey number and Team Name\nplay_scout['vises'] = play_scout['vises'].str.replace(\" \",\"\")\nplay_scout['jersyV']=play_scout['vises'].str[3:]\nplay_scout['vises'] = play_scout['vises'].str[:3]","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.740801Z","iopub.execute_input":"2022-01-04T18:10:15.741026Z","iopub.status.idle":"2022-01-04T18:10:15.838185Z","shell.execute_reply.started":"2022-01-04T18:10:15.740990Z","shell.execute_reply":"2022-01-04T18:10:15.837412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_columns', None)\nplay_scout.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.839481Z","iopub.execute_input":"2022-01-04T18:10:15.839746Z","iopub.status.idle":"2022-01-04T18:10:15.885113Z","shell.execute_reply.started":"2022-01-04T18:10:15.839713Z","shell.execute_reply":"2022-01-04T18:10:15.884148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"track.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.886645Z","iopub.execute_input":"2022-01-04T18:10:15.887144Z","iopub.status.idle":"2022-01-04T18:10:15.898860Z","shell.execute_reply.started":"2022-01-04T18:10:15.887097Z","shell.execute_reply":"2022-01-04T18:10:15.897812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.900793Z","iopub.execute_input":"2022-01-04T18:10:15.901101Z","iopub.status.idle":"2022-01-04T18:10:15.909956Z","shell.execute_reply.started":"2022-01-04T18:10:15.901039Z","shell.execute_reply":"2022-01-04T18:10:15.908104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#change data type to float\nplay_scout['jersyMT'] = play_scout['jersyMT'].astype(np.float)\nplay_scout['jersyAT'] = play_scout['jersyAT'].astype(np.float)\nplay_scout['jersyT'] = play_scout['jersyT'].astype(np.float)\nplay_scout['jersyG'] = play_scout['jersyG'].astype(np.float)\nplay_scout['jersyPR'] = play_scout['jersyPR'].astype(np.float)\nplay_scout['jersySTS'] = play_scout['jersySTS'].astype(np.float)\nplay_scout['jersyV'] = play_scout['jersyV'].astype(np.float)\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.911253Z","iopub.execute_input":"2022-01-04T18:10:15.911696Z","iopub.status.idle":"2022-01-04T18:10:15.977458Z","shell.execute_reply.started":"2022-01-04T18:10:15.911666Z","shell.execute_reply":"2022-01-04T18:10:15.976827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Merging Play scout and Track dataframe","metadata":{}},{"cell_type":"code","source":"#merging play scout and track based on Missed Tackler Player\nplay_scout = pd.merge(play_scout, track, how='left',left_on=['jersyMT','gameId','playId','missedTackler'],right_on=['jerseyNumber','gameId','playId','teamName'])\n\n#clean un used coulumn\ndel play_scout['jerseyNumber']\ndel play_scout['teamName']\n\nplay_scout = play_scout.rename(columns={\"nflId\": \"MTId\"})\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:15.978678Z","iopub.execute_input":"2022-01-04T18:10:15.978898Z","iopub.status.idle":"2022-01-04T18:10:16.250147Z","shell.execute_reply.started":"2022-01-04T18:10:15.978869Z","shell.execute_reply":"2022-01-04T18:10:16.249420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#merging play scout and track based on Assist Tackler Player\nplay_scout = pd.merge(play_scout, track, how='left',left_on=['jersyAT','gameId','playId','assistTackler'],right_on=['jerseyNumber','gameId','playId','teamName'])\n#clean un used coulumn\ndel play_scout['jerseyNumber']\ndel play_scout['teamName']\nplay_scout = play_scout.rename(columns={\"nflId\": \"ATId\"})\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:16.253390Z","iopub.execute_input":"2022-01-04T18:10:16.253590Z","iopub.status.idle":"2022-01-04T18:10:16.531874Z","shell.execute_reply.started":"2022-01-04T18:10:16.253564Z","shell.execute_reply":"2022-01-04T18:10:16.531087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#merging play scout and track based on  Tackler Player\nplay_scout = pd.merge(play_scout, track, how='left',left_on=['jersyT','gameId','playId','tackler'],right_on=['jerseyNumber','gameId','playId','teamName'])\n#clean un used coulumn\ndel play_scout['jerseyNumber']\ndel play_scout['teamName']\nplay_scout = play_scout.rename(columns={\"nflId\": \"TId\"})\n\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:16.533149Z","iopub.execute_input":"2022-01-04T18:10:16.533397Z","iopub.status.idle":"2022-01-04T18:10:16.815823Z","shell.execute_reply.started":"2022-01-04T18:10:16.533365Z","shell.execute_reply":"2022-01-04T18:10:16.814916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#merging play scout and track based on  Gunners Player\nplay_scout = pd.merge(play_scout, track, how='left',left_on=['jersyG','gameId','playId','gunners'],right_on=['jerseyNumber','gameId','playId','teamName'])\ndel play_scout['jerseyNumber']\ndel play_scout['teamName']\nplay_scout = play_scout.rename(columns={\"nflId\": \"GId\"})","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:16.817186Z","iopub.execute_input":"2022-01-04T18:10:16.817451Z","iopub.status.idle":"2022-01-04T18:10:17.108376Z","shell.execute_reply.started":"2022-01-04T18:10:16.817415Z","shell.execute_reply":"2022-01-04T18:10:17.107641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#merging play scout and track based on  Punt Rusher Player\nplay_scout = pd.merge(play_scout, track, how='left',left_on=['jersyPR','gameId','playId','puntRushers'],right_on=['jerseyNumber','gameId','playId','teamName'])\ndel play_scout['jerseyNumber']\ndel play_scout['teamName']\nplay_scout = play_scout.rename(columns={\"nflId\": \"PRId\"})","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:17.109677Z","iopub.execute_input":"2022-01-04T18:10:17.109909Z","iopub.status.idle":"2022-01-04T18:10:17.392402Z","shell.execute_reply.started":"2022-01-04T18:10:17.109878Z","shell.execute_reply":"2022-01-04T18:10:17.391654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#merging play scout and track based on  specialTeamsSafeties Player\nplay_scout = pd.merge(play_scout, track, how='left',left_on=['jersySTS','gameId','playId','specialTeamsSafeties'],right_on=['jerseyNumber','gameId','playId','teamName'])\ndel play_scout['jerseyNumber']\ndel play_scout['teamName']\nplay_scout = play_scout.rename(columns={\"nflId\": \"STSId\"})\n\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:17.393863Z","iopub.execute_input":"2022-01-04T18:10:17.394127Z","iopub.status.idle":"2022-01-04T18:10:17.695663Z","shell.execute_reply.started":"2022-01-04T18:10:17.394093Z","shell.execute_reply":"2022-01-04T18:10:17.694796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#merging play scout and track based on  vises Player\nplay_scout = pd.merge(play_scout, track, how='left',left_on=['jersyV','gameId','playId','vises'],right_on=['jerseyNumber','gameId','playId','teamName'])\ndel play_scout['jerseyNumber']\ndel play_scout['teamName']\nplay_scout = play_scout.rename(columns={\"nflId\": \"VId\"})","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:17.697246Z","iopub.execute_input":"2022-01-04T18:10:17.697735Z","iopub.status.idle":"2022-01-04T18:10:18.004278Z","shell.execute_reply.started":"2022-01-04T18:10:17.697692Z","shell.execute_reply":"2022-01-04T18:10:18.003489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:18.005664Z","iopub.execute_input":"2022-01-04T18:10:18.005933Z","iopub.status.idle":"2022-01-04T18:10:18.078508Z","shell.execute_reply.started":"2022-01-04T18:10:18.005897Z","shell.execute_reply":"2022-01-04T18:10:18.077767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 5. Merge player and play_scout to define College name","metadata":{}},{"cell_type":"code","source":"#merging play_scout and player \nplay_scout = pd.merge(play_scout, players, how='left', left_on=['MTId'],right_on=['nflId'])\ndel play_scout['nflId']\nplay_scout = play_scout.rename(columns={\"collegeName\": \"MTCollege\"})","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:18.079762Z","iopub.execute_input":"2022-01-04T18:10:18.080066Z","iopub.status.idle":"2022-01-04T18:10:18.311383Z","shell.execute_reply.started":"2022-01-04T18:10:18.080026Z","shell.execute_reply":"2022-01-04T18:10:18.310643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout = pd.merge(play_scout, players, how='left', left_on=['ATId'],right_on=['nflId'])\ndel play_scout['nflId']\nplay_scout = play_scout.rename(columns={\"collegeName\": \"ATCollege\"})","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:18.312873Z","iopub.execute_input":"2022-01-04T18:10:18.313298Z","iopub.status.idle":"2022-01-04T18:10:18.561028Z","shell.execute_reply.started":"2022-01-04T18:10:18.313262Z","shell.execute_reply":"2022-01-04T18:10:18.560284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout = pd.merge(play_scout, players, how='left', left_on=['TId'],right_on=['nflId'])\ndel play_scout['nflId']\nplay_scout = play_scout.rename(columns={\"collegeName\": \"TCollege\"})","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:18.562467Z","iopub.execute_input":"2022-01-04T18:10:18.562750Z","iopub.status.idle":"2022-01-04T18:10:18.819725Z","shell.execute_reply.started":"2022-01-04T18:10:18.562714Z","shell.execute_reply":"2022-01-04T18:10:18.817751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout = pd.merge(play_scout, players, how='left', left_on=['GId'],right_on=['nflId'])\ndel play_scout['nflId']\nplay_scout = play_scout.rename(columns={\"collegeName\": \"GCollege\"})","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:18.821465Z","iopub.execute_input":"2022-01-04T18:10:18.821907Z","iopub.status.idle":"2022-01-04T18:10:19.176997Z","shell.execute_reply.started":"2022-01-04T18:10:18.821863Z","shell.execute_reply":"2022-01-04T18:10:19.176262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout = pd.merge(play_scout, players, how='left', left_on=['PRId'],right_on=['nflId'])\ndel play_scout['nflId']\nplay_scout = play_scout.rename(columns={\"collegeName\": \"PRCollege\"})","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:19.178219Z","iopub.execute_input":"2022-01-04T18:10:19.178475Z","iopub.status.idle":"2022-01-04T18:10:19.452710Z","shell.execute_reply.started":"2022-01-04T18:10:19.178442Z","shell.execute_reply":"2022-01-04T18:10:19.451943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout = pd.merge(play_scout, players, how='left', left_on=['STSId'],right_on=['nflId'])\ndel play_scout['nflId']\nplay_scout = play_scout.rename(columns={\"collegeName\": \"STSCollege\"})","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:19.453992Z","iopub.execute_input":"2022-01-04T18:10:19.454797Z","iopub.status.idle":"2022-01-04T18:10:19.734098Z","shell.execute_reply.started":"2022-01-04T18:10:19.454750Z","shell.execute_reply":"2022-01-04T18:10:19.733354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout = pd.merge(play_scout, players, how='left', left_on=['VId'],right_on=['nflId'])\ndel play_scout['nflId']\nplay_scout = play_scout.rename(columns={\"collegeName\": \"VCollege\"})","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:19.735230Z","iopub.execute_input":"2022-01-04T18:10:19.735705Z","iopub.status.idle":"2022-01-04T18:10:20.022801Z","shell.execute_reply.started":"2022-01-04T18:10:19.735666Z","shell.execute_reply":"2022-01-04T18:10:20.022034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:20.023969Z","iopub.execute_input":"2022-01-04T18:10:20.024870Z","iopub.status.idle":"2022-01-04T18:10:20.086146Z","shell.execute_reply.started":"2022-01-04T18:10:20.024829Z","shell.execute_reply":"2022-01-04T18:10:20.085460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 6. Encoding","metadata":{}},{"cell_type":"code","source":"# Import label encoder\nfrom sklearn import preprocessing\n \n# label_encoder object knows how to understand word labels.\nlabel_encoder = preprocessing.LabelEncoder()\n \n# Encode labels in column 'species'.\nplay_scout['specialTeamsPlayType_cat']= label_encoder.fit_transform(play_scout['specialTeamsPlayType'])\nplay_scout['specialTeamsResult_cat']= label_encoder.fit_transform(play_scout['specialTeamsResult'])\nplay_scout['passResult_cat']= label_encoder.fit_transform(play_scout['passResult'].astype(str))\nplay_scout['kickType_cat']= label_encoder.fit_transform(play_scout['kickType'].astype(str))\nplay_scout['kickContactType_cat']= label_encoder.fit_transform(play_scout['kickContactType'].astype(str))\nplay_scout['kickerCollege_cat']= label_encoder.fit_transform(play_scout['kickerCollege'].astype(str))\nplay_scout['returnerCollege_cat']= label_encoder.fit_transform(play_scout['returnerCollege'].astype(str))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:20.088394Z","iopub.execute_input":"2022-01-04T18:10:20.089132Z","iopub.status.idle":"2022-01-04T18:10:20.950048Z","shell.execute_reply.started":"2022-01-04T18:10:20.089095Z","shell.execute_reply":"2022-01-04T18:10:20.949176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_scout.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:20.951434Z","iopub.execute_input":"2022-01-04T18:10:20.951718Z","iopub.status.idle":"2022-01-04T18:10:21.012200Z","shell.execute_reply.started":"2022-01-04T18:10:20.951682Z","shell.execute_reply":"2022-01-04T18:10:21.011516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## **BUILD MODEL & MATRIX EVALUATION**","metadata":{}},{"cell_type":"markdown","source":"## **Feature and Target Selection**\n\nAfter the pre-processing stage is complete, the selected feature will be used for data mining and modelling algorithm implementation.","metadata":{}},{"cell_type":"code","source":"pd.set_option('display.max_columns', None)\nplay_scout.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:21.013245Z","iopub.execute_input":"2022-01-04T18:10:21.013525Z","iopub.status.idle":"2022-01-04T18:10:21.072108Z","shell.execute_reply.started":"2022-01-04T18:10:21.013489Z","shell.execute_reply":"2022-01-04T18:10:21.071427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataModel = play_scout[['specialTeamsPlayType_cat','kickType_cat' , 'kickContactType_cat', 'kickAccuracy', 'returnAccuracy', 'kickLength', 'hangTime','playResult','eventScore','specialTeamsResult_cat']]","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:21.073381Z","iopub.execute_input":"2022-01-04T18:10:21.073820Z","iopub.status.idle":"2022-01-04T18:10:21.086194Z","shell.execute_reply.started":"2022-01-04T18:10:21.073770Z","shell.execute_reply":"2022-01-04T18:10:21.085351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataModel = dataModel.dropna()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:21.087571Z","iopub.execute_input":"2022-01-04T18:10:21.087864Z","iopub.status.idle":"2022-01-04T18:10:21.098343Z","shell.execute_reply.started":"2022-01-04T18:10:21.087827Z","shell.execute_reply":"2022-01-04T18:10:21.097739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataModel.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:21.099615Z","iopub.execute_input":"2022-01-04T18:10:21.099865Z","iopub.status.idle":"2022-01-04T18:10:21.108206Z","shell.execute_reply.started":"2022-01-04T18:10:21.099832Z","shell.execute_reply":"2022-01-04T18:10:21.107437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Feature and Target Selection\nfeature = dataModel[['specialTeamsPlayType_cat','kickType_cat' , 'kickContactType_cat', 'kickAccuracy', 'returnAccuracy', 'kickLength', 'hangTime','playResult']]\ntarget = dataModel[['eventScore']]","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:21.109466Z","iopub.execute_input":"2022-01-04T18:10:21.109765Z","iopub.status.idle":"2022-01-04T18:10:21.117542Z","shell.execute_reply.started":"2022-01-04T18:10:21.109730Z","shell.execute_reply":"2022-01-04T18:10:21.116830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## **Modelling and Evaluation Matrix**\n\n1. We do the data mining techniques in this step. This process aims to extract potential patterns to obtain useful data that will be used to solve existing problems. We use traditional methods, namely Decission Tree, Random Forest, KNN, Linear Regression, SGD, SVC and advanced algorithms, namely SVM,MLP, and CNN. It aims to compare the method used to determine the toughness of the algorithm being tested.\n2. At this evaluation part, the results of data mining techniques in the form of typical patterns and predictive models are evaluated to assess whether the existing hypothesis is indeed achieved. We will use Evaluation metrics such as recall, f-1 score, and precision.\n\nI purposely run data modeling individually for each algorithm so that the data splitting process is also different and the data is randomized as a whole for each model","metadata":{}},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:21.119031Z","iopub.execute_input":"2022-01-04T18:10:21.119324Z","iopub.status.idle":"2022-01-04T18:10:21.126081Z","shell.execute_reply.started":"2022-01-04T18:10:21.119289Z","shell.execute_reply":"2022-01-04T18:10:21.125397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1. KNN","metadata":{}},{"cell_type":"code","source":"# Import train_test_split function\nfrom sklearn.model_selection import train_test_split\n\n# Split dataset into training set and test set\nX_train, X_test, y_train, y_test = train_test_split(feature, target, test_size=0.3, shuffle=True) # 70% training and 30% test","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:21.127750Z","iopub.execute_input":"2022-01-04T18:10:21.127991Z","iopub.status.idle":"2022-01-04T18:10:21.176880Z","shell.execute_reply.started":"2022-01-04T18:10:21.127960Z","shell.execute_reply":"2022-01-04T18:10:21.176268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Import knearest neighbors Classifier model\nfrom sklearn.neighbors import KNeighborsClassifier\n\n#Create KNN Classifier\nknn = KNeighborsClassifier(n_neighbors=5)\n\n#Train the model using the training sets\nknn.fit(X_train, y_train.values.ravel())\n\n#Predict the response for test dataset\ny_pred = knn.predict(X_test)\n\n#Predict the response for test dataset\nx_pred = knn.predict(X_train)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:21.178390Z","iopub.execute_input":"2022-01-04T18:10:21.178686Z","iopub.status.idle":"2022-01-04T18:10:24.918852Z","shell.execute_reply.started":"2022-01-04T18:10:21.178661Z","shell.execute_reply":"2022-01-04T18:10:24.918089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import classification_report,confusion_matrix\n\n#Confusion Matrix for Training Data\nprint(confusion_matrix(y_train,x_pred))\nprint(classification_report(y_train,x_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:24.920267Z","iopub.execute_input":"2022-01-04T18:10:24.920679Z","iopub.status.idle":"2022-01-04T18:10:25.072627Z","shell.execute_reply.started":"2022-01-04T18:10:24.920640Z","shell.execute_reply":"2022-01-04T18:10:25.071810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Testing Data\nprint(confusion_matrix(y_test,y_pred))\nprint(classification_report(y_test,y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:25.074052Z","iopub.execute_input":"2022-01-04T18:10:25.074309Z","iopub.status.idle":"2022-01-04T18:10:25.141366Z","shell.execute_reply.started":"2022-01-04T18:10:25.074275Z","shell.execute_reply":"2022-01-04T18:10:25.140582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 2. RF","metadata":{}},{"cell_type":"code","source":"# Import train_test_split function\nfrom sklearn.model_selection import train_test_split\n\n# Split dataset into training set and test set\nX_train, X_test, y_train, y_test = train_test_split(feature, target, test_size=0.3, shuffle=True) # 70% training and 30% test","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:25.142705Z","iopub.execute_input":"2022-01-04T18:10:25.142957Z","iopub.status.idle":"2022-01-04T18:10:25.156271Z","shell.execute_reply.started":"2022-01-04T18:10:25.142923Z","shell.execute_reply":"2022-01-04T18:10:25.155620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Import knearest neighbors Classifier model\nfrom sklearn.ensemble import RandomForestClassifier\n\n#Create KNN Classifier\nrf = RandomForestClassifier()\n\n#Train the model using the training sets\nrf.fit(X_train, y_train.values.ravel())\n\n#Predict the response for test dataset\ny_pred = rf.predict(X_test)\n\nx_pred =rf.predict(X_train)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:25.157383Z","iopub.execute_input":"2022-01-04T18:10:25.158010Z","iopub.status.idle":"2022-01-04T18:10:29.303286Z","shell.execute_reply.started":"2022-01-04T18:10:25.157975Z","shell.execute_reply":"2022-01-04T18:10:29.302577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Training Data\nfrom sklearn.metrics import classification_report,confusion_matrix\nprint(confusion_matrix(y_train,x_pred))\nprint(classification_report(y_train,x_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:29.304659Z","iopub.execute_input":"2022-01-04T18:10:29.304919Z","iopub.status.idle":"2022-01-04T18:10:29.458713Z","shell.execute_reply.started":"2022-01-04T18:10:29.304885Z","shell.execute_reply":"2022-01-04T18:10:29.457999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Testing Data\nprint(confusion_matrix(y_test,y_pred))\nprint(classification_report(y_test,y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:29.459809Z","iopub.execute_input":"2022-01-04T18:10:29.460236Z","iopub.status.idle":"2022-01-04T18:10:29.530964Z","shell.execute_reply.started":"2022-01-04T18:10:29.460198Z","shell.execute_reply":"2022-01-04T18:10:29.530139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 3. Decission Tree","metadata":{}},{"cell_type":"code","source":"# Import train_test_split function\nfrom sklearn.model_selection import train_test_split\n\n# Split dataset into training set and test set\nX_train, X_test, y_train, y_test = train_test_split(feature, target, test_size=0.3, shuffle=True) # 70% training and 30% test","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:29.532306Z","iopub.execute_input":"2022-01-04T18:10:29.532563Z","iopub.status.idle":"2022-01-04T18:10:29.546084Z","shell.execute_reply.started":"2022-01-04T18:10:29.532523Z","shell.execute_reply":"2022-01-04T18:10:29.545384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.tree import DecisionTreeClassifier\n\nDT = DecisionTreeClassifier()\n\n#Train the model using the training sets\nDT.fit(X_train, y_train.values.ravel())\n\n#Predict the response for test dataset\ny_pred = DT.predict(X_test)\n\nx_pred = DT.predict(X_train)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:29.556640Z","iopub.execute_input":"2022-01-04T18:10:29.557215Z","iopub.status.idle":"2022-01-04T18:10:29.715887Z","shell.execute_reply.started":"2022-01-04T18:10:29.557180Z","shell.execute_reply":"2022-01-04T18:10:29.715232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Training Data\nfrom sklearn.metrics import classification_report,confusion_matrix\nprint(confusion_matrix(y_train,x_pred))\nprint(classification_report(y_train,x_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:29.717085Z","iopub.execute_input":"2022-01-04T18:10:29.717606Z","iopub.status.idle":"2022-01-04T18:10:29.869894Z","shell.execute_reply.started":"2022-01-04T18:10:29.717551Z","shell.execute_reply":"2022-01-04T18:10:29.869080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Testing Data\nprint(confusion_matrix(y_test,y_pred))\nprint(classification_report(y_test,y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:29.871350Z","iopub.execute_input":"2022-01-04T18:10:29.871615Z","iopub.status.idle":"2022-01-04T18:10:29.940246Z","shell.execute_reply.started":"2022-01-04T18:10:29.871568Z","shell.execute_reply":"2022-01-04T18:10:29.939609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 4. SVC","metadata":{}},{"cell_type":"code","source":"# Import train_test_split function\nfrom sklearn.model_selection import train_test_split\n\n# Split dataset into training set and test set\nX_train, X_test, y_train, y_test = train_test_split(feature, target, test_size=0.3, shuffle=True) # 70% training and 30% test","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:29.941287Z","iopub.execute_input":"2022-01-04T18:10:29.942016Z","iopub.status.idle":"2022-01-04T18:10:29.955580Z","shell.execute_reply.started":"2022-01-04T18:10:29.941978Z","shell.execute_reply":"2022-01-04T18:10:29.954914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Import Logistic SVC model\nfrom sklearn.svm import SVC, LinearSVC\n\n#Create KNN Classifier\nSVC = SVC()\n\n#Train the model using the training sets\nSVC.fit(X_train, y_train.values.ravel())\n\n#Predict the response for test dataset\ny_pred = SVC.predict(X_test)\n\nx_pred =SVC.predict(X_train)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:29.956874Z","iopub.execute_input":"2022-01-04T18:10:29.957127Z","iopub.status.idle":"2022-01-04T18:10:45.855701Z","shell.execute_reply.started":"2022-01-04T18:10:29.957095Z","shell.execute_reply":"2022-01-04T18:10:45.854940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Training Data\nfrom sklearn.metrics import classification_report,confusion_matrix\nprint(confusion_matrix(y_train,x_pred))\nprint(classification_report(y_train,x_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:45.856983Z","iopub.execute_input":"2022-01-04T18:10:45.857220Z","iopub.status.idle":"2022-01-04T18:10:46.007719Z","shell.execute_reply.started":"2022-01-04T18:10:45.857188Z","shell.execute_reply":"2022-01-04T18:10:46.006882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Testing Data\nprint(confusion_matrix(y_test,y_pred))\nprint(classification_report(y_test,y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:46.009192Z","iopub.execute_input":"2022-01-04T18:10:46.009477Z","iopub.status.idle":"2022-01-04T18:10:46.077623Z","shell.execute_reply.started":"2022-01-04T18:10:46.009440Z","shell.execute_reply":"2022-01-04T18:10:46.076925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 5. Linier SVC","metadata":{}},{"cell_type":"code","source":"# Import train_test_split function\nfrom sklearn.model_selection import train_test_split\n\n# Split dataset into training set and test set\nX_train, X_test, y_train, y_test = train_test_split(feature, target, test_size=0.3, shuffle=True) # 70% training and 30% test","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:46.078798Z","iopub.execute_input":"2022-01-04T18:10:46.079206Z","iopub.status.idle":"2022-01-04T18:10:46.093033Z","shell.execute_reply.started":"2022-01-04T18:10:46.079168Z","shell.execute_reply":"2022-01-04T18:10:46.092344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Import Logistic SVC model\nfrom sklearn.svm import SVC, LinearSVC\n\n#Create KNN Classifier\nLSVC = LinearSVC()\n\n#Train the model using the training sets\nLSVC.fit(X_train, y_train.values.ravel())\n\n#Predict the response for test dataset\ny_pred = LSVC.predict(X_test)\n\nx_pred = LSVC.predict(X_train)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:46.094544Z","iopub.execute_input":"2022-01-04T18:10:46.095116Z","iopub.status.idle":"2022-01-04T18:10:49.986636Z","shell.execute_reply.started":"2022-01-04T18:10:46.095080Z","shell.execute_reply":"2022-01-04T18:10:49.985815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Training Data\nfrom sklearn.metrics import classification_report,confusion_matrix\nprint(confusion_matrix(y_train,x_pred))\nprint(classification_report(y_train,x_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:49.987731Z","iopub.execute_input":"2022-01-04T18:10:49.988123Z","iopub.status.idle":"2022-01-04T18:10:50.195248Z","shell.execute_reply.started":"2022-01-04T18:10:49.988089Z","shell.execute_reply":"2022-01-04T18:10:50.194563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Testing Data\nprint(confusion_matrix(y_test,y_pred))\nprint(classification_report(y_test,y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:50.196445Z","iopub.execute_input":"2022-01-04T18:10:50.196737Z","iopub.status.idle":"2022-01-04T18:10:50.266227Z","shell.execute_reply.started":"2022-01-04T18:10:50.196702Z","shell.execute_reply":"2022-01-04T18:10:50.265425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 6. SGD","metadata":{}},{"cell_type":"code","source":"# Import train_test_split function\nfrom sklearn.model_selection import train_test_split\n\n# Split dataset into training set and test set\nX_train, X_test, y_train, y_test = train_test_split(feature, target, test_size=0.3, shuffle=True) # 70% training and 30% test","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:50.267445Z","iopub.execute_input":"2022-01-04T18:10:50.267858Z","iopub.status.idle":"2022-01-04T18:10:50.282642Z","shell.execute_reply.started":"2022-01-04T18:10:50.267819Z","shell.execute_reply":"2022-01-04T18:10:50.282004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression, Ridge, SGDClassifier\n\nSGD = SGDClassifier()\n\n#Train the model using the training sets\nSGD.fit(X_train, y_train.values.ravel())\n\n#Predict the response for test dataset\ny_pred = SGD.predict(X_test)\n\nx_pred =SGD.predict(X_train)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:50.283769Z","iopub.execute_input":"2022-01-04T18:10:50.284427Z","iopub.status.idle":"2022-01-04T18:10:51.014814Z","shell.execute_reply.started":"2022-01-04T18:10:50.284372Z","shell.execute_reply":"2022-01-04T18:10:51.013927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Training Data\nfrom sklearn.metrics import classification_report,confusion_matrix\nprint(confusion_matrix(y_train,x_pred))\nprint(classification_report(y_train,x_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:51.016201Z","iopub.execute_input":"2022-01-04T18:10:51.016726Z","iopub.status.idle":"2022-01-04T18:10:51.222041Z","shell.execute_reply.started":"2022-01-04T18:10:51.016688Z","shell.execute_reply":"2022-01-04T18:10:51.221343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Testing Data\nprint(confusion_matrix(y_test,y_pred))\nprint(classification_report(y_test,y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:51.223178Z","iopub.execute_input":"2022-01-04T18:10:51.223433Z","iopub.status.idle":"2022-01-04T18:10:51.292280Z","shell.execute_reply.started":"2022-01-04T18:10:51.223399Z","shell.execute_reply":"2022-01-04T18:10:51.291481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 7. MLP","metadata":{}},{"cell_type":"code","source":"# Import train_test_split function\nfrom sklearn.model_selection import train_test_split\n\n# Split dataset into training set and test set\nX_train, X_test, y_train, y_test = train_test_split(feature, target, test_size=0.3, shuffle=True) # 70% training and 30% test","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:51.293504Z","iopub.execute_input":"2022-01-04T18:10:51.293835Z","iopub.status.idle":"2022-01-04T18:10:51.307901Z","shell.execute_reply.started":"2022-01-04T18:10:51.293800Z","shell.execute_reply":"2022-01-04T18:10:51.307245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.neural_network import MLPClassifier\n\nmlp = MLPClassifier(hidden_layer_sizes=(8,8,8), activation='relu', solver='adam', max_iter=500)\nmlp.fit(X_train,y_train)\n\npredict_train = mlp.predict(X_train)\npredict_test = mlp.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:51.309160Z","iopub.execute_input":"2022-01-04T18:10:51.309419Z","iopub.status.idle":"2022-01-04T18:10:57.430066Z","shell.execute_reply.started":"2022-01-04T18:10:51.309387Z","shell.execute_reply":"2022-01-04T18:10:57.429141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Training Data\nfrom sklearn.metrics import classification_report,confusion_matrix\nprint(confusion_matrix(y_train,predict_train))\nprint(classification_report(y_train,predict_train))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:57.431225Z","iopub.execute_input":"2022-01-04T18:10:57.433955Z","iopub.status.idle":"2022-01-04T18:10:57.638980Z","shell.execute_reply.started":"2022-01-04T18:10:57.433907Z","shell.execute_reply":"2022-01-04T18:10:57.638246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Testing Data\nprint(confusion_matrix(y_test,predict_test))\nprint(classification_report(y_test,predict_test))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:57.640242Z","iopub.execute_input":"2022-01-04T18:10:57.640650Z","iopub.status.idle":"2022-01-04T18:10:57.708604Z","shell.execute_reply.started":"2022-01-04T18:10:57.640612Z","shell.execute_reply":"2022-01-04T18:10:57.707864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 8. CNN","metadata":{}},{"cell_type":"code","source":"# Import train_test_split function\nfrom sklearn.model_selection import train_test_split\n\n# Split dataset into training set and test set\nX_train, X_test, y_train, y_test = train_test_split(feature, target, test_size=0.3, shuffle=True) # 70% training and 30% test","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:57.709871Z","iopub.execute_input":"2022-01-04T18:10:57.710124Z","iopub.status.idle":"2022-01-04T18:10:57.723371Z","shell.execute_reply.started":"2022-01-04T18:10:57.710091Z","shell.execute_reply":"2022-01-04T18:10:57.722537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Importing the Keras libraries and packages\nimport keras\nfrom keras.models import Sequential\nfrom keras.layers import Dense\n\n# Initialising the ANN\nclassifier = Sequential()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:10:57.724533Z","iopub.execute_input":"2022-01-04T18:10:57.724982Z","iopub.status.idle":"2022-01-04T18:11:04.149802Z","shell.execute_reply.started":"2022-01-04T18:10:57.724915Z","shell.execute_reply":"2022-01-04T18:11:04.149026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Adding the input layer and the first hidden layer\nclassifier.add(Dense(units = 16, kernel_initializer = 'uniform', activation = 'relu', input_dim =8))\n\n# Adding the second hidden layer\nclassifier.add(Dense(units = 16, kernel_initializer = 'uniform', activation = 'relu'))\n\n# Adding the output layer\nclassifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))\n\n# Compiling the ANN\nclassifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:11:04.151159Z","iopub.execute_input":"2022-01-04T18:11:04.151570Z","iopub.status.idle":"2022-01-04T18:11:04.208545Z","shell.execute_reply.started":"2022-01-04T18:11:04.151533Z","shell.execute_reply":"2022-01-04T18:11:04.207890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Fitting the ANN to the Training set\nclassifier.fit(X_train, y_train, batch_size = 10, epochs = 10)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:11:04.209658Z","iopub.execute_input":"2022-01-04T18:11:04.209892Z","iopub.status.idle":"2022-01-04T18:13:03.648086Z","shell.execute_reply.started":"2022-01-04T18:11:04.209859Z","shell.execute_reply":"2022-01-04T18:13:03.647413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Predicting the Test set results\ny_pred = classifier.predict(X_test)\ny_pred = (y_pred > 0.5)\n\nx_pred = classifier.predict(X_train)\nx_pred = (x_pred > 0.5)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:13:03.649328Z","iopub.execute_input":"2022-01-04T18:13:03.649916Z","iopub.status.idle":"2022-01-04T18:13:05.556477Z","shell.execute_reply.started":"2022-01-04T18:13:03.649877Z","shell.execute_reply":"2022-01-04T18:13:05.555750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Training Data\nfrom sklearn.metrics import classification_report,confusion_matrix\nprint(confusion_matrix(y_train,x_pred))\nprint(classification_report(y_train,x_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:13:05.557659Z","iopub.execute_input":"2022-01-04T18:13:05.557915Z","iopub.status.idle":"2022-01-04T18:13:05.815567Z","shell.execute_reply.started":"2022-01-04T18:13:05.557883Z","shell.execute_reply":"2022-01-04T18:13:05.814853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Testing Data\nprint(confusion_matrix(y_test,y_pred))\nprint(classification_report(y_test,y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:13:05.816890Z","iopub.execute_input":"2022-01-04T18:13:05.817127Z","iopub.status.idle":"2022-01-04T18:13:05.931804Z","shell.execute_reply.started":"2022-01-04T18:13:05.817094Z","shell.execute_reply":"2022-01-04T18:13:05.931087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 10. SVM","metadata":{}},{"cell_type":"code","source":"# Import train_test_split function\nfrom sklearn.model_selection import train_test_split\n\n# Split dataset into training set and test set\nX_train, X_test, y_train, y_test = train_test_split(feature, target, test_size=0.2) # 70% training and 30% test","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:13:05.932902Z","iopub.execute_input":"2022-01-04T18:13:05.933371Z","iopub.status.idle":"2022-01-04T18:13:05.946576Z","shell.execute_reply.started":"2022-01-04T18:13:05.933332Z","shell.execute_reply":"2022-01-04T18:13:05.945928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Import svm model\nfrom sklearn import svm\n\n#Create a svm Classifier\nclf = svm.SVC(kernel='linear') # Linear Kernel\n\n#Train the model using the training sets\nclf.fit(X_train, y_train)\n\n#Predict the response for test dataset\ny_pred = clf.predict(X_test)\n\nx_pred = clf.predict(X_train)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:13:05.947672Z","iopub.execute_input":"2022-01-04T18:13:05.947983Z","iopub.status.idle":"2022-01-04T18:23:14.949666Z","shell.execute_reply.started":"2022-01-04T18:13:05.947947Z","shell.execute_reply":"2022-01-04T18:23:14.948877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Training Data\nfrom sklearn.metrics import classification_report,confusion_matrix\nprint(confusion_matrix(y_train,x_pred))\nprint(classification_report(y_train,x_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:14.950884Z","iopub.execute_input":"2022-01-04T18:23:14.951154Z","iopub.status.idle":"2022-01-04T18:23:15.125669Z","shell.execute_reply.started":"2022-01-04T18:23:14.951121Z","shell.execute_reply":"2022-01-04T18:23:15.124824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix for Testing Data\nprint(confusion_matrix(y_test,y_pred))\nprint(classification_report(y_test,y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:15.127122Z","iopub.execute_input":"2022-01-04T18:23:15.127417Z","iopub.status.idle":"2022-01-04T18:23:15.176193Z","shell.execute_reply.started":"2022-01-04T18:23:15.127381Z","shell.execute_reply":"2022-01-04T18:23:15.175467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **PART II. KNOWLEDGE GRAPH**","metadata":{}},{"cell_type":"markdown","source":"### **DATA PREPARATION**","metadata":{}},{"cell_type":"code","source":"dfgraph= play_scout[['kickerId', 'returnerId', 'specialTeamsResult', 'kickerCollege','returnerCollege', 'eventScore', 'MTId', 'ATId', 'TId', 'GId', 'PRId', 'STSId', 'VId', 'MTCollege', 'ATCollege', 'TCollege', 'GCollege', 'PRCollege', 'STSCollege', 'VCollege']] \ndfgraph.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:15.177403Z","iopub.execute_input":"2022-01-04T18:23:15.177661Z","iopub.status.idle":"2022-01-04T18:23:15.210383Z","shell.execute_reply.started":"2022-01-04T18:23:15.177625Z","shell.execute_reply":"2022-01-04T18:23:15.209663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## GNN","metadata":{}},{"cell_type":"markdown","source":"## 1. Kicker Returner Relation","metadata":{}},{"cell_type":"code","source":"dfgraphKR= dfgraph[['kickerId', 'returnerId', 'specialTeamsResult', 'kickerCollege','returnerCollege', 'eventScore']] ","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:15.211819Z","iopub.execute_input":"2022-01-04T18:23:15.212297Z","iopub.status.idle":"2022-01-04T18:23:15.219840Z","shell.execute_reply.started":"2022-01-04T18:23:15.212235Z","shell.execute_reply":"2022-01-04T18:23:15.218989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKR.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:15.221476Z","iopub.execute_input":"2022-01-04T18:23:15.222088Z","iopub.status.idle":"2022-01-04T18:23:15.253129Z","shell.execute_reply.started":"2022-01-04T18:23:15.222048Z","shell.execute_reply":"2022-01-04T18:23:15.252385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKR.dropna(subset = [\"kickerId\"], inplace=True)\ndfgraphKR.dropna(subset = [\"returnerId\"], inplace=True)\ndfgraphKR.dropna(subset = [\"kickerCollege\"], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:15.254298Z","iopub.execute_input":"2022-01-04T18:23:15.254605Z","iopub.status.idle":"2022-01-04T18:23:15.276714Z","shell.execute_reply.started":"2022-01-04T18:23:15.254559Z","shell.execute_reply":"2022-01-04T18:23:15.276081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKR = dfgraphKR.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:15.278374Z","iopub.execute_input":"2022-01-04T18:23:15.278831Z","iopub.status.idle":"2022-01-04T18:23:15.283637Z","shell.execute_reply.started":"2022-01-04T18:23:15.278797Z","shell.execute_reply":"2022-01-04T18:23:15.282938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#define team name for each player based on home team and visitor team\nfor x in range(len(dfgraphKR)-1):\n  if dfgraphKR.loc[x, 'kickerCollege'] == dfgraphKR.loc[x, 'returnerCollege']:\n    dfgraphKR.loc[x, 'KRCollege'] = 1\n  else:\n    dfgraphKR.loc[x, 'KRCollege'] = 0","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:15.286380Z","iopub.execute_input":"2022-01-04T18:23:15.287363Z","iopub.status.idle":"2022-01-04T18:23:32.617862Z","shell.execute_reply.started":"2022-01-04T18:23:15.287335Z","shell.execute_reply":"2022-01-04T18:23:32.617113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKR.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:32.619170Z","iopub.execute_input":"2022-01-04T18:23:32.619429Z","iopub.status.idle":"2022-01-04T18:23:32.633079Z","shell.execute_reply.started":"2022-01-04T18:23:32.619396Z","shell.execute_reply":"2022-01-04T18:23:32.632417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKR['kickerId'] =dfgraphKR['kickerId'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:32.634329Z","iopub.execute_input":"2022-01-04T18:23:32.634754Z","iopub.status.idle":"2022-01-04T18:23:32.643753Z","shell.execute_reply.started":"2022-01-04T18:23:32.634717Z","shell.execute_reply":"2022-01-04T18:23:32.642973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Graph Construction and Visualization","metadata":{}},{"cell_type":"code","source":"GDirectKR = nx.from_pandas_edgelist(dfgraphKR,source='kickerId',target='returnerId', create_using=nx.DiGraph(),edge_attr='specialTeamsResult')","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:32.645641Z","iopub.execute_input":"2022-01-04T18:23:32.646048Z","iopub.status.idle":"2022-01-04T18:23:32.857531Z","shell.execute_reply.started":"2022-01-04T18:23:32.646014Z","shell.execute_reply":"2022-01-04T18:23:32.856920Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"degCent = nx.degree_centrality(GDirectKR)\nnode_color = ['orange' if type(v)==float else 'green' for v in GDirectKR]\nnode_size =  [v * 10000 for v in degCent.values()]\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GDirectKR, with_labels=True,\n                 node_color=node_color,\n                 node_size=node_size)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:32.858720Z","iopub.execute_input":"2022-01-04T18:23:32.858957Z","iopub.status.idle":"2022-01-04T18:23:56.140447Z","shell.execute_reply.started":"2022-01-04T18:23:32.858923Z","shell.execute_reply":"2022-01-04T18:23:56.139674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### College Relation","metadata":{}},{"cell_type":"code","source":"#college team\n\nGCollegeKR = nx.from_pandas_edgelist(dfgraphKR,source='kickerCollege',target='returnerCollege', create_using=nx.DiGraph(),edge_attr='KRCollege')","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:56.141511Z","iopub.execute_input":"2022-01-04T18:23:56.141777Z","iopub.status.idle":"2022-01-04T18:23:56.340605Z","shell.execute_reply.started":"2022-01-04T18:23:56.141738Z","shell.execute_reply":"2022-01-04T18:23:56.339889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"color = [\n\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\"]","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:56.342328Z","iopub.execute_input":"2022-01-04T18:23:56.342603Z","iopub.status.idle":"2022-01-04T18:23:56.367730Z","shell.execute_reply.started":"2022-01-04T18:23:56.342555Z","shell.execute_reply":"2022-01-04T18:23:56.366804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"colors = []\ni = 0\nfor node in GCollegeKR:\n    if node in dfgraphKR[\"kickerId\"].values:\n      colors.append(\"navy\")  \n    elif node in dfgraphKR[\"returnerId\"].values:\n      colors.append(\"lightgreen\")\n    else:\n        colors.append(color[i])\n        i+=1","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:56.369032Z","iopub.execute_input":"2022-01-04T18:23:56.369670Z","iopub.status.idle":"2022-01-04T18:23:56.385134Z","shell.execute_reply.started":"2022-01-04T18:23:56.369629Z","shell.execute_reply":"2022-01-04T18:23:56.384449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"degCent = nx.degree_centrality(GCollegeKR)\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GCollegeKR, with_labels=True,\n                 node_color=colors,\n                 node_size=1200)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:23:56.386271Z","iopub.execute_input":"2022-01-04T18:23:56.387001Z","iopub.status.idle":"2022-01-04T18:24:14.117284Z","shell.execute_reply.started":"2022-01-04T18:23:56.386938Z","shell.execute_reply":"2022-01-04T18:24:14.116514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"![Kicker And Returner Relationship With Others Player Type](https://drive.google.com/file/d/1bn9eT9lHND8gqGVwm6PA3fBbN1PuRTaE/view?usp=sharing)\n\n","metadata":{}},{"cell_type":"markdown","source":"## 2. Relation between Kicker and Other Player Type","metadata":{}},{"cell_type":"markdown","source":"### 2.1 Kicker and Gunners Relation","metadata":{}},{"cell_type":"code","source":"dfgraphKG= dfgraph[['kickerId', 'GId', 'specialTeamsResult', 'kickerCollege','GCollege', 'eventScore']] ","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:14.118891Z","iopub.execute_input":"2022-01-04T18:24:14.119355Z","iopub.status.idle":"2022-01-04T18:24:14.126106Z","shell.execute_reply.started":"2022-01-04T18:24:14.119319Z","shell.execute_reply":"2022-01-04T18:24:14.125493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKG.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:14.127343Z","iopub.execute_input":"2022-01-04T18:24:14.127738Z","iopub.status.idle":"2022-01-04T18:24:14.172188Z","shell.execute_reply.started":"2022-01-04T18:24:14.127705Z","shell.execute_reply":"2022-01-04T18:24:14.171641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKG.dropna(subset = [\"kickerId\"], inplace=True)\ndfgraphKG.dropna(subset = [\"GId\"], inplace=True)\ndfgraphKG.dropna(subset = [\"GCollege\"], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:14.173319Z","iopub.execute_input":"2022-01-04T18:24:14.173704Z","iopub.status.idle":"2022-01-04T18:24:14.195683Z","shell.execute_reply.started":"2022-01-04T18:24:14.173672Z","shell.execute_reply":"2022-01-04T18:24:14.194999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKG['kickerId'] =dfgraphKG['kickerId'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:14.196800Z","iopub.execute_input":"2022-01-04T18:24:14.197468Z","iopub.status.idle":"2022-01-04T18:24:14.202027Z","shell.execute_reply.started":"2022-01-04T18:24:14.197432Z","shell.execute_reply":"2022-01-04T18:24:14.201337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Graph Construction and Visualization","metadata":{}},{"cell_type":"code","source":"GDirectKG = nx.from_pandas_edgelist(dfgraphKG,source='kickerId',target='GId', create_using=nx.DiGraph(),edge_attr='specialTeamsResult')","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:14.203341Z","iopub.execute_input":"2022-01-04T18:24:14.203893Z","iopub.status.idle":"2022-01-04T18:24:14.297100Z","shell.execute_reply.started":"2022-01-04T18:24:14.203854Z","shell.execute_reply":"2022-01-04T18:24:14.296477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"degCent = nx.degree_centrality(GDirectKG)\nnode_color = ['orange' if type(v)==float else 'green' for v in GDirectKG]\nnode_size =  [v * 10000 for v in degCent.values()]\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GDirectKG, with_labels=True,\n                 node_color=node_color,\n                 node_size=node_size)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:14.298507Z","iopub.execute_input":"2022-01-04T18:24:14.298972Z","iopub.status.idle":"2022-01-04T18:24:16.862948Z","shell.execute_reply.started":"2022-01-04T18:24:14.298937Z","shell.execute_reply":"2022-01-04T18:24:16.862120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### College Relation","metadata":{}},{"cell_type":"code","source":"#college team\n\nGCollegeKG = nx.from_pandas_edgelist(dfgraphKG,source='kickerCollege',target='GCollege', create_using=nx.DiGraph(),edge_attr='eventScore')\n\ncolor = [\n\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\"]\n\ncolors = []\ni = 0\nfor node in GCollegeKG:\n    if node in dfgraphKG[\"kickerId\"].values:\n      colors.append(\"navy\")  \n    elif node in dfgraphKG[\"GId\"].values:\n      colors.append(\"lightgreen\")\n    else:\n        colors.append(color[i])\n        i+=1\n\n        \n#ploting graph\ndegCent = nx.degree_centrality(GCollegeKG)\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GCollegeKG, with_labels=True,\n                 node_color=colors,\n                 node_size=1200)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:16.864508Z","iopub.execute_input":"2022-01-04T18:24:16.864921Z","iopub.status.idle":"2022-01-04T18:24:19.695032Z","shell.execute_reply.started":"2022-01-04T18:24:16.864888Z","shell.execute_reply":"2022-01-04T18:24:19.694436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2.2. Kicker and Tackler Relation","metadata":{}},{"cell_type":"code","source":"dfgraphKT= dfgraph[['kickerId', 'TId', 'specialTeamsResult', 'kickerCollege','TCollege', 'eventScore']] ","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:19.696285Z","iopub.execute_input":"2022-01-04T18:24:19.696723Z","iopub.status.idle":"2022-01-04T18:24:19.703561Z","shell.execute_reply.started":"2022-01-04T18:24:19.696679Z","shell.execute_reply":"2022-01-04T18:24:19.702962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKT.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:19.704991Z","iopub.execute_input":"2022-01-04T18:24:19.705429Z","iopub.status.idle":"2022-01-04T18:24:19.744032Z","shell.execute_reply.started":"2022-01-04T18:24:19.705388Z","shell.execute_reply":"2022-01-04T18:24:19.743262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKT.dropna(subset = [\"kickerId\"], inplace=True)\ndfgraphKT.dropna(subset = [\"TId\"], inplace=True)\ndfgraphKT.dropna(subset = [\"TCollege\"], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:19.745375Z","iopub.execute_input":"2022-01-04T18:24:19.745630Z","iopub.status.idle":"2022-01-04T18:24:19.762279Z","shell.execute_reply.started":"2022-01-04T18:24:19.745585Z","shell.execute_reply":"2022-01-04T18:24:19.761577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKT['kickerId'] =dfgraphKT['kickerId'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:19.763759Z","iopub.execute_input":"2022-01-04T18:24:19.763936Z","iopub.status.idle":"2022-01-04T18:24:19.769570Z","shell.execute_reply.started":"2022-01-04T18:24:19.763914Z","shell.execute_reply":"2022-01-04T18:24:19.768750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Graph Construction and Visualization","metadata":{}},{"cell_type":"code","source":"GDirectKT = nx.from_pandas_edgelist(dfgraphKT,source='kickerId',target='TId', create_using=nx.DiGraph(),edge_attr='specialTeamsResult')\n\ndegCent = nx.degree_centrality(GDirectKT)\nnode_color = ['orange' if type(v)==float else 'green' for v in GDirectKT]\nnode_size =  [v * 10000 for v in degCent.values()]\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GDirectKT, with_labels=True,\n                 node_color=node_color,\n                 node_size=node_size)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:19.771170Z","iopub.execute_input":"2022-01-04T18:24:19.771478Z","iopub.status.idle":"2022-01-04T18:24:27.193663Z","shell.execute_reply.started":"2022-01-04T18:24:19.771414Z","shell.execute_reply":"2022-01-04T18:24:27.192864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### College Relation","metadata":{}},{"cell_type":"code","source":"#college team\n\nGCollegeKT = nx.from_pandas_edgelist(dfgraphKT,source='kickerCollege',target='TCollege', create_using=nx.DiGraph(),edge_attr='eventScore')\n\ncolor = [\n\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\"]\n\ncolors = []\ni = 0\nfor node in GCollegeKT:\n    if node in dfgraphKT[\"kickerId\"].values:\n      colors.append(\"navy\")  \n    elif node in dfgraphKT[\"TId\"].values:\n      colors.append(\"lightgreen\")\n    else:\n        colors.append(color[i])\n        i+=1\n\n        \n#ploting graph\ndegCent = nx.degree_centrality(GCollegeKT)\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GCollegeKT, with_labels=True,\n                 node_color=colors,\n                 node_size=1200)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:27.195025Z","iopub.execute_input":"2022-01-04T18:24:27.195366Z","iopub.status.idle":"2022-01-04T18:24:34.855154Z","shell.execute_reply.started":"2022-01-04T18:24:27.195335Z","shell.execute_reply":"2022-01-04T18:24:34.852651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2.3 Kicker and Asist Tackler Relation ","metadata":{}},{"cell_type":"code","source":"dfgraphKAT= dfgraph[['kickerId', 'ATId', 'specialTeamsResult', 'kickerCollege','ATCollege', 'eventScore']] ","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:34.856554Z","iopub.execute_input":"2022-01-04T18:24:34.856811Z","iopub.status.idle":"2022-01-04T18:24:34.863807Z","shell.execute_reply.started":"2022-01-04T18:24:34.856779Z","shell.execute_reply":"2022-01-04T18:24:34.863182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKAT.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:34.865045Z","iopub.execute_input":"2022-01-04T18:24:34.865489Z","iopub.status.idle":"2022-01-04T18:24:34.910371Z","shell.execute_reply.started":"2022-01-04T18:24:34.865455Z","shell.execute_reply":"2022-01-04T18:24:34.909722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKAT.dropna(subset = [\"kickerId\"], inplace=True)\ndfgraphKAT.dropna(subset = [\"ATId\"], inplace=True)\ndfgraphKAT.dropna(subset = [\"ATCollege\"], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:34.911688Z","iopub.execute_input":"2022-01-04T18:24:34.912119Z","iopub.status.idle":"2022-01-04T18:24:34.928376Z","shell.execute_reply.started":"2022-01-04T18:24:34.912083Z","shell.execute_reply":"2022-01-04T18:24:34.927783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphKAT['kickerId'] =dfgraphKAT['kickerId'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:34.930425Z","iopub.execute_input":"2022-01-04T18:24:34.930806Z","iopub.status.idle":"2022-01-04T18:24:34.935514Z","shell.execute_reply.started":"2022-01-04T18:24:34.930771Z","shell.execute_reply":"2022-01-04T18:24:34.934853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Graph Construction and Visualization","metadata":{}},{"cell_type":"code","source":"GDirectKAT = nx.from_pandas_edgelist(dfgraphKAT,source='kickerId',target='ATId', create_using=nx.DiGraph(),edge_attr='specialTeamsResult')\n\ndegCent = nx.degree_centrality(GDirectKAT)\nnode_color = ['orange' if type(v)==float else 'green' for v in GDirectKAT]\nnode_size =  [v * 10000 for v in degCent.values()]\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GDirectKAT, with_labels=True,\n                 node_color=node_color,\n                 node_size=node_size)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:34.936879Z","iopub.execute_input":"2022-01-04T18:24:34.937385Z","iopub.status.idle":"2022-01-04T18:24:38.249956Z","shell.execute_reply.started":"2022-01-04T18:24:34.937304Z","shell.execute_reply":"2022-01-04T18:24:38.248937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### College Relation Between Kicker and Assist Tackler","metadata":{}},{"cell_type":"code","source":"#college team\n\nGCollegeKAT = nx.from_pandas_edgelist(dfgraphKAT,source='kickerCollege',target='ATCollege', create_using=nx.DiGraph(),edge_attr='eventScore')\n\ncolor = [\n\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\"]\n\ncolors = []\ni = 0\nfor node in GCollegeKAT:\n    if node in dfgraphKAT[\"kickerId\"].values:\n      colors.append(\"navy\")  \n    elif node in dfgraphKAT[\"ATId\"].values:\n      colors.append(\"lightgreen\")\n    else:\n        colors.append(color[i])\n        i+=1\n\n        \n#ploting graph\ndegCent = nx.degree_centrality(GCollegeKAT)\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GCollegeKAT, with_labels=True,\n                 node_color=colors,\n                 node_size=1200)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:38.251355Z","iopub.execute_input":"2022-01-04T18:24:38.251770Z","iopub.status.idle":"2022-01-04T18:24:41.601107Z","shell.execute_reply.started":"2022-01-04T18:24:38.251737Z","shell.execute_reply":"2022-01-04T18:24:41.600419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 3. Relation between Retuner and Other Player Type","metadata":{}},{"cell_type":"markdown","source":"### 3.1 Returner and Punt Rusher Relation","metadata":{}},{"cell_type":"code","source":"dfgraphRPR= dfgraph[['returnerId', 'PRId', 'specialTeamsResult', 'returnerCollege','PRCollege', 'eventScore']] ","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:41.602383Z","iopub.execute_input":"2022-01-04T18:24:41.603003Z","iopub.status.idle":"2022-01-04T18:24:41.611394Z","shell.execute_reply.started":"2022-01-04T18:24:41.602968Z","shell.execute_reply":"2022-01-04T18:24:41.610804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphRPR.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:41.612481Z","iopub.execute_input":"2022-01-04T18:24:41.613039Z","iopub.status.idle":"2022-01-04T18:24:41.646067Z","shell.execute_reply.started":"2022-01-04T18:24:41.613004Z","shell.execute_reply":"2022-01-04T18:24:41.645363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphRPR.dropna(subset = [\"returnerId\"], inplace=True)\ndfgraphRPR.dropna(subset = [\"PRId\"], inplace=True)\ndfgraphRPR.dropna(subset = [\"PRCollege\"], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:41.647307Z","iopub.execute_input":"2022-01-04T18:24:41.647555Z","iopub.status.idle":"2022-01-04T18:24:41.663175Z","shell.execute_reply.started":"2022-01-04T18:24:41.647522Z","shell.execute_reply":"2022-01-04T18:24:41.662561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphRPR['returnerId'] =dfgraphRPR['returnerId'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:41.664403Z","iopub.execute_input":"2022-01-04T18:24:41.664663Z","iopub.status.idle":"2022-01-04T18:24:41.669311Z","shell.execute_reply.started":"2022-01-04T18:24:41.664628Z","shell.execute_reply":"2022-01-04T18:24:41.668645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Graph Construction and Visualization","metadata":{}},{"cell_type":"code","source":"GDirectRPR = nx.from_pandas_edgelist(dfgraphRPR,source='returnerId',target='PRId', create_using=nx.DiGraph(),edge_attr='specialTeamsResult')\n\ndegCent = nx.degree_centrality(GDirectRPR)\nnode_color = ['red' if type(v)==float else 'blue' for v in GDirectRPR]\nnode_size =  [v * 10000 for v in degCent.values()]\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GDirectRPR, with_labels=True,\n                 node_color=node_color,\n                 node_size=node_size)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:41.670732Z","iopub.execute_input":"2022-01-04T18:24:41.671269Z","iopub.status.idle":"2022-01-04T18:24:48.920364Z","shell.execute_reply.started":"2022-01-04T18:24:41.671234Z","shell.execute_reply":"2022-01-04T18:24:48.919564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### College Relation Between Returner and Punt Rusher","metadata":{}},{"cell_type":"code","source":"#college team\n\nGCollegeRPR = nx.from_pandas_edgelist(dfgraphRPR,source='returnerCollege',target='PRCollege', create_using=nx.DiGraph(),edge_attr='eventScore')\n\ncolor = [\n\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\"]\n\ncolors = []\ni = 0\nfor node in GCollegeRPR:\n    if node in dfgraphRPR[\"returnerId\"].values:\n      colors.append(\"navy\")  \n    elif node in dfgraphRPR[\"PRId\"].values:\n      colors.append(\"lightgreen\")\n    else:\n        colors.append(color[i])\n        i+=1\n\n        \n#ploting graph\ndegCent = nx.degree_centrality(GCollegeRPR)\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GCollegeRPR, with_labels=True,\n                 node_color=colors,\n                 node_size=1200)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:48.925027Z","iopub.execute_input":"2022-01-04T18:24:48.925272Z","iopub.status.idle":"2022-01-04T18:24:55.013969Z","shell.execute_reply.started":"2022-01-04T18:24:48.925241Z","shell.execute_reply":"2022-01-04T18:24:55.012241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 3.2 Returner and STS Relation","metadata":{}},{"cell_type":"code","source":"dfgraphRSTS= dfgraph[['returnerId', 'STSId', 'specialTeamsResult', 'returnerCollege','STSCollege', 'eventScore']] ","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:55.016247Z","iopub.execute_input":"2022-01-04T18:24:55.016505Z","iopub.status.idle":"2022-01-04T18:24:55.025551Z","shell.execute_reply.started":"2022-01-04T18:24:55.016473Z","shell.execute_reply":"2022-01-04T18:24:55.024678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphRSTS.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:55.028810Z","iopub.execute_input":"2022-01-04T18:24:55.029090Z","iopub.status.idle":"2022-01-04T18:24:55.068122Z","shell.execute_reply.started":"2022-01-04T18:24:55.029053Z","shell.execute_reply":"2022-01-04T18:24:55.067480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphRSTS.dropna(subset = [\"returnerId\"], inplace=True)\ndfgraphRSTS.dropna(subset = [\"STSId\"], inplace=True)\ndfgraphRSTS.dropna(subset = [\"STSCollege\"], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:55.069213Z","iopub.execute_input":"2022-01-04T18:24:55.069849Z","iopub.status.idle":"2022-01-04T18:24:55.085488Z","shell.execute_reply.started":"2022-01-04T18:24:55.069822Z","shell.execute_reply":"2022-01-04T18:24:55.084880Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphRSTS['returnerId'] =dfgraphRSTS['returnerId'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:55.086689Z","iopub.execute_input":"2022-01-04T18:24:55.086922Z","iopub.status.idle":"2022-01-04T18:24:55.092945Z","shell.execute_reply.started":"2022-01-04T18:24:55.086890Z","shell.execute_reply":"2022-01-04T18:24:55.091179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Graph Construction and Visualization","metadata":{}},{"cell_type":"code","source":"GDirectRSTS = nx.from_pandas_edgelist(dfgraphRSTS,source='returnerId',target='STSId', create_using=nx.DiGraph(),edge_attr='specialTeamsResult')\n\ndegCent = nx.degree_centrality(GDirectRSTS)\nnode_color = ['red' if type(v)==float else 'blue' for v in GDirectRSTS]\nnode_size =  [v * 10000 for v in degCent.values()]\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GDirectRSTS, with_labels=True,\n                 node_color=node_color,\n                 node_size=node_size)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:24:55.094337Z","iopub.execute_input":"2022-01-04T18:24:55.094763Z","iopub.status.idle":"2022-01-04T18:25:05.187030Z","shell.execute_reply.started":"2022-01-04T18:24:55.094726Z","shell.execute_reply":"2022-01-04T18:25:05.186425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### College Relation Between Returner and STS","metadata":{}},{"cell_type":"code","source":"#college team\n\nGCollegeRSTS = nx.from_pandas_edgelist(dfgraphRSTS,source='returnerCollege',target='STSCollege', create_using=nx.DiGraph(),edge_attr='eventScore')\n\ncolor = [\n\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\"]\n\ncolors = []\ni = 0\nfor node in GCollegeRSTS:\n    if node in dfgraphRSTS[\"returnerId\"].values:\n      colors.append(\"navy\")  \n    elif node in dfgraphRSTS[\"STSId\"].values:\n      colors.append(\"lightgreen\")\n    else:\n        colors.append(color[i])\n        i+=1\n\n        \n#ploting graph\ndegCent = nx.degree_centrality(GCollegeRSTS)\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GCollegeRSTS, with_labels=True,\n                 node_color=colors,\n                 node_size=1200)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:25:05.188695Z","iopub.execute_input":"2022-01-04T18:25:05.189123Z","iopub.status.idle":"2022-01-04T18:25:15.833980Z","shell.execute_reply.started":"2022-01-04T18:25:05.189088Z","shell.execute_reply":"2022-01-04T18:25:15.831700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 3.3 Returner and Vises Relation","metadata":{}},{"cell_type":"code","source":"dfgraphRV= dfgraph[['returnerId', 'VId', 'specialTeamsResult', 'returnerCollege','VCollege', 'eventScore']] ","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:25:15.835271Z","iopub.execute_input":"2022-01-04T18:25:15.835692Z","iopub.status.idle":"2022-01-04T18:25:15.843033Z","shell.execute_reply.started":"2022-01-04T18:25:15.835659Z","shell.execute_reply":"2022-01-04T18:25:15.842371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphRV.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:25:15.844531Z","iopub.execute_input":"2022-01-04T18:25:15.845085Z","iopub.status.idle":"2022-01-04T18:25:15.887212Z","shell.execute_reply.started":"2022-01-04T18:25:15.845017Z","shell.execute_reply":"2022-01-04T18:25:15.886400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphRV.dropna(subset = [\"returnerId\"], inplace=True)\ndfgraphRV.dropna(subset = [\"VId\"], inplace=True)\ndfgraphRV.dropna(subset = [\"VCollege\"], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:25:15.888562Z","iopub.execute_input":"2022-01-04T18:25:15.888835Z","iopub.status.idle":"2022-01-04T18:25:15.904833Z","shell.execute_reply.started":"2022-01-04T18:25:15.888800Z","shell.execute_reply":"2022-01-04T18:25:15.904221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraphRV['returnerId'] =dfgraphRV['returnerId'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:25:15.906087Z","iopub.execute_input":"2022-01-04T18:25:15.906351Z","iopub.status.idle":"2022-01-04T18:25:15.910813Z","shell.execute_reply.started":"2022-01-04T18:25:15.906319Z","shell.execute_reply":"2022-01-04T18:25:15.910096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Graph Construction and Visualization","metadata":{}},{"cell_type":"code","source":"GDirectRV = nx.from_pandas_edgelist(dfgraphRV,source='returnerId',target='VId', create_using=nx.DiGraph(),edge_attr='specialTeamsResult')\n\ndegCent = nx.degree_centrality(GDirectRV)\nnode_color = ['red' if type(v)==float else 'blue' for v in GDirectRV]\nnode_size =  [v * 10000 for v in degCent.values()]\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GDirectRV, with_labels=True,\n                 node_color=node_color,\n                 node_size=node_size)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:25:15.911992Z","iopub.execute_input":"2022-01-04T18:25:15.912924Z","iopub.status.idle":"2022-01-04T18:25:21.280360Z","shell.execute_reply.started":"2022-01-04T18:25:15.912887Z","shell.execute_reply":"2022-01-04T18:25:21.279574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### College Relation Between Returner and Vises","metadata":{}},{"cell_type":"code","source":"#college team\n\nGCollegeRV = nx.from_pandas_edgelist(dfgraphRV,source='returnerCollege',target='VCollege', create_using=nx.DiGraph(),edge_attr='eventScore')\n\ncolor = [\n\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\",\"lightcoral\", \"gray\", \"lightgray\", \"firebrick\", \"red\", \"chocolate\", \"darkorange\", \"moccasin\", \"gold\", \"yellow\", \"darkolivegreen\", \"chartreuse\", \"forestgreen\", \"lime\", \"mediumaquamarine\", \"turquoise\", \"teal\", \"cadetblue\", \"purple\", \"blue\", \"slateblue\", \"blueviolet\", \"magenta\", \"lightsteelblue\",\"orange\",\"green\",\"navy\"]\n\ncolors = []\ni = 0\nfor node in GCollegeRV:\n    if node in dfgraphRV[\"returnerId\"].values:\n      colors.append(\"navy\")  \n    elif node in dfgraphRV[\"VId\"].values:\n      colors.append(\"lightgreen\")\n    else:\n        colors.append(color[i])\n        i+=1\n\n        \n#ploting graph\ndegCent = nx.degree_centrality(GCollegeRV)\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(GCollegeRV, with_labels=True,\n                 node_color=colors,\n                 node_size=1200)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:25:21.282316Z","iopub.execute_input":"2022-01-04T18:25:21.282617Z","iopub.status.idle":"2022-01-04T18:25:26.267418Z","shell.execute_reply.started":"2022-01-04T18:25:21.282576Z","shell.execute_reply":"2022-01-04T18:25:26.266766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## GRAPH ANALYSIS","metadata":{}},{"cell_type":"markdown","source":"### Now, we want to construct the graph that representing the Special Teams Play Type with GameId so we can find the most Play Type that have been using in NFL American Football By Special Teams\n","metadata":{"editable":false}},{"cell_type":"code","source":"#now, we want to construct the graph that representing the Special Teams Play Type with GameId so we can find the most Play Type that have been using in NFL American Football By Special Teams\n\n# Add all columns in the table as edge attribute\nG = nx.from_pandas_edgelist(play_scout, 'gameId', 'specialTeamsPlayType', edge_attr=True )","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:25:26.268419Z","iopub.execute_input":"2022-01-04T18:25:26.268762Z","iopub.status.idle":"2022-01-04T18:25:27.629649Z","shell.execute_reply.started":"2022-01-04T18:25:26.268730Z","shell.execute_reply":"2022-01-04T18:25:27.628579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Add all columns in the table as edge attribute\nG2 = nx.from_pandas_edgelist(play_scout, 'gameId', 'specialTeamsResult', edge_attr=True )","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:25:27.631772Z","iopub.execute_input":"2022-01-04T18:25:27.632274Z","iopub.status.idle":"2022-01-04T18:25:28.982524Z","shell.execute_reply.started":"2022-01-04T18:25:27.632234Z","shell.execute_reply":"2022-01-04T18:25:28.981791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"degCent = nx.degree_centrality(G)\nnode_color = ['orange' if type(v)==int else 'green' for v in G]\nnode_size =  [v * 10000 for v in degCent.values()]\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(G, with_labels=True,\n                 node_color=node_color,\n                 node_size=node_size)\n\nplt.show()\n\n\n#From the graph below  we can see that the most Play type that have been using by Special Team is \"Kickoff\"","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-01-04T18:25:28.983694Z","iopub.execute_input":"2022-01-04T18:25:28.983952Z","iopub.status.idle":"2022-01-04T18:25:36.086253Z","shell.execute_reply.started":"2022-01-04T18:25:28.983919Z","shell.execute_reply":"2022-01-04T18:25:36.085402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Besides, we can also construct the graph that representing the Special Teams Result with GameId so we can find the most Special Teams strategie resulted in NFL American Football we can achieve it using degree of centrality\n","metadata":{"editable":false}},{"cell_type":"code","source":"\ndegCent = nx.degree_centrality(G2)\nnode_color = ['blue' if type(v)==int else 'red' for v in G2]\nnode_size =  [v * 10000 for v in degCent.values()]\nplt.figure(figsize=(20,20))\n\n# draw figure with customized options\nnx.draw(G2, with_labels=True,\n                 node_color=node_color,\n                 node_size=node_size)\n\nplt.show()\n\n\n#From the graph below  we can see that the most Result is \"Return\"","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-01-04T18:25:36.087564Z","iopub.execute_input":"2022-01-04T18:25:36.087816Z","iopub.status.idle":"2022-01-04T18:25:44.102416Z","shell.execute_reply.started":"2022-01-04T18:25:36.087785Z","shell.execute_reply":"2022-01-04T18:25:44.101774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### GNN","metadata":{}},{"cell_type":"code","source":"!pip install torch","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:25:44.103390Z","iopub.execute_input":"2022-01-04T18:25:44.103735Z","iopub.status.idle":"2022-01-04T18:25:52.469448Z","shell.execute_reply.started":"2022-01-04T18:25:44.103703Z","shell.execute_reply":"2022-01-04T18:25:52.468613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install --verbose --no-cache-dir torch-scatter\n!pip install --verbose --no-cache-dir torch-sparse","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:25:52.471405Z","iopub.execute_input":"2022-01-04T18:25:52.471705Z","iopub.status.idle":"2022-01-04T18:54:34.218988Z","shell.execute_reply.started":"2022-01-04T18:25:52.471666Z","shell.execute_reply":"2022-01-04T18:54:34.218099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install torch_geometric","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:34.224073Z","iopub.execute_input":"2022-01-04T18:54:34.226146Z","iopub.status.idle":"2022-01-04T18:54:44.585907Z","shell.execute_reply.started":"2022-01-04T18:54:34.226105Z","shell.execute_reply":"2022-01-04T18:54:44.584665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport pickle\nimport csv\nimport os\nimport torch\nfrom torch_geometric.data import InMemoryDataset, Dataset, Data","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:44.587384Z","iopub.execute_input":"2022-01-04T18:54:44.587663Z","iopub.status.idle":"2022-01-04T18:54:47.211563Z","shell.execute_reply.started":"2022-01-04T18:54:44.587624Z","shell.execute_reply":"2022-01-04T18:54:47.210644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.random.seed(42)\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.213182Z","iopub.execute_input":"2022-01-04T18:54:47.213475Z","iopub.status.idle":"2022-01-04T18:54:47.219010Z","shell.execute_reply.started":"2022-01-04T18:54:47.213435Z","shell.execute_reply":"2022-01-04T18:54:47.218324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraph.nunique()\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.220102Z","iopub.execute_input":"2022-01-04T18:54:47.220866Z","iopub.status.idle":"2022-01-04T18:54:47.299201Z","shell.execute_reply.started":"2022-01-04T18:54:47.220828Z","shell.execute_reply":"2022-01-04T18:54:47.298463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfgraph.isna().sum()\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.300249Z","iopub.execute_input":"2022-01-04T18:54:47.300501Z","iopub.status.idle":"2022-01-04T18:54:47.358398Z","shell.execute_reply.started":"2022-01-04T18:54:47.300467Z","shell.execute_reply":"2022-01-04T18:54:47.357648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_KR = dfgraph[['kickerCollege','returnerCollege','kickerId','returnerId','specialTeamsResult', 'eventScore',]]\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.359585Z","iopub.execute_input":"2022-01-04T18:54:47.359913Z","iopub.status.idle":"2022-01-04T18:54:47.367158Z","shell.execute_reply.started":"2022-01-04T18:54:47.359877Z","shell.execute_reply":"2022-01-04T18:54:47.366365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_KR.isna().sum()\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.368708Z","iopub.execute_input":"2022-01-04T18:54:47.369970Z","iopub.status.idle":"2022-01-04T18:54:47.403466Z","shell.execute_reply.started":"2022-01-04T18:54:47.369765Z","shell.execute_reply":"2022-01-04T18:54:47.402574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_KR=df_KR.dropna()\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.404861Z","iopub.execute_input":"2022-01-04T18:54:47.405654Z","iopub.status.idle":"2022-01-04T18:54:47.437415Z","shell.execute_reply.started":"2022-01-04T18:54:47.405595Z","shell.execute_reply":"2022-01-04T18:54:47.436736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_KR.isna().sum()\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.439992Z","iopub.execute_input":"2022-01-04T18:54:47.440181Z","iopub.status.idle":"2022-01-04T18:54:47.460803Z","shell.execute_reply.started":"2022-01-04T18:54:47.440158Z","shell.execute_reply":"2022-01-04T18:54:47.460058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# average length of kickerCollege \ndfgraph.groupby('kickerCollege')['returnerCollege'].size().mean()\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.462004Z","iopub.execute_input":"2022-01-04T18:54:47.462388Z","iopub.status.idle":"2022-01-04T18:54:47.478850Z","shell.execute_reply.started":"2022-01-04T18:54:47.462352Z","shell.execute_reply":"2022-01-04T18:54:47.477914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\n\nitem_encoder = LabelEncoder()\ndf_KR['kickerId'] = item_encoder.fit_transform(df_KR.kickerId)\ndf_KR.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.480640Z","iopub.execute_input":"2022-01-04T18:54:47.481074Z","iopub.status.idle":"2022-01-04T18:54:47.498134Z","shell.execute_reply.started":"2022-01-04T18:54:47.481041Z","shell.execute_reply":"2022-01-04T18:54:47.497484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"item_encoder = LabelEncoder()\ndf_KR['specialTeamsResult'] = item_encoder.fit_transform(df_KR.specialTeamsResult)\ndf_KR.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.499188Z","iopub.execute_input":"2022-01-04T18:54:47.499916Z","iopub.status.idle":"2022-01-04T18:54:47.526204Z","shell.execute_reply.started":"2022-01-04T18:54:47.499879Z","shell.execute_reply":"2022-01-04T18:54:47.525499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"item_encoder = LabelEncoder()\ndf_KR['returnerId'] = item_encoder.fit_transform(df_KR.returnerId)\ndf_KR.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.527227Z","iopub.execute_input":"2022-01-04T18:54:47.527462Z","iopub.status.idle":"2022-01-04T18:54:47.543289Z","shell.execute_reply.started":"2022-01-04T18:54:47.527428Z","shell.execute_reply":"2022-01-04T18:54:47.542495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"item_encoder = LabelEncoder()\ndf_KR['returnerCollege'] = item_encoder.fit_transform(df_KR.returnerCollege)\ndf_KR.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.544395Z","iopub.execute_input":"2022-01-04T18:54:47.544758Z","iopub.status.idle":"2022-01-04T18:54:47.572581Z","shell.execute_reply.started":"2022-01-04T18:54:47.544718Z","shell.execute_reply":"2022-01-04T18:54:47.571815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"item_encoder = LabelEncoder()\ndf_KR['kickerCollege'] = item_encoder.fit_transform(df_KR.kickerCollege)\ndf_KR.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.575198Z","iopub.execute_input":"2022-01-04T18:54:47.575376Z","iopub.status.idle":"2022-01-04T18:54:47.600332Z","shell.execute_reply.started":"2022-01-04T18:54:47.575354Z","shell.execute_reply":"2022-01-04T18:54:47.599507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_KR =df_KR.reset_index(drop=True)\n","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.601742Z","iopub.execute_input":"2022-01-04T18:54:47.601984Z","iopub.status.idle":"2022-01-04T18:54:47.609262Z","shell.execute_reply.started":"2022-01-04T18:54:47.601952Z","shell.execute_reply":"2022-01-04T18:54:47.608384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### To check wheter kicker and returner are from same college","metadata":{}},{"cell_type":"code","source":"for x in range(len(df_KR)-1):\n  if df_KR.loc[x,'kickerCollege'] == df_KR.loc[x,'returnerCollege']:\n    df_KR.loc[x,'label'] = True\n  else:\n   df_KR.loc[x,'label'] = False","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:54:47.610830Z","iopub.execute_input":"2022-01-04T18:54:47.611281Z","iopub.status.idle":"2022-01-04T18:55:25.523612Z","shell.execute_reply.started":"2022-01-04T18:54:47.611243Z","shell.execute_reply":"2022-01-04T18:55:25.522853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_KR.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:55:25.525018Z","iopub.execute_input":"2022-01-04T18:55:25.525263Z","iopub.status.idle":"2022-01-04T18:55:25.539833Z","shell.execute_reply.started":"2022-01-04T18:55:25.525229Z","shell.execute_reply":"2022-01-04T18:55:25.539212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# display wheter kicker and returner are from same college\ndf_KR.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:55:25.540937Z","iopub.execute_input":"2022-01-04T18:55:25.541240Z","iopub.status.idle":"2022-01-04T18:55:25.555407Z","shell.execute_reply.started":"2022-01-04T18:55:25.541205Z","shell.execute_reply":"2022-01-04T18:55:25.554678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_KR.groupby('label').sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:55:25.557171Z","iopub.execute_input":"2022-01-04T18:55:25.557762Z","iopub.status.idle":"2022-01-04T18:55:25.579224Z","shell.execute_reply.started":"2022-01-04T18:55:25.557722Z","shell.execute_reply":"2022-01-04T18:55:25.578615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_KR.drop_duplicates('kickerCollege')['label'].mean()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:55:25.580441Z","iopub.execute_input":"2022-01-04T18:55:25.580918Z","iopub.status.idle":"2022-01-04T18:55:25.590343Z","shell.execute_reply.started":"2022-01-04T18:55:25.580883Z","shell.execute_reply":"2022-01-04T18:55:25.589608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kick_return = dict(df_KR.groupby('kickerId')['returnerId'].apply(list))\n#kick_return","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:55:25.591481Z","iopub.execute_input":"2022-01-04T18:55:25.591804Z","iopub.status.idle":"2022-01-04T18:55:25.609473Z","shell.execute_reply.started":"2022-01-04T18:55:25.591769Z","shell.execute_reply":"2022-01-04T18:55:25.608845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nfrom torch_geometric.data import InMemoryDataset, Data\nfrom tqdm import tqdm\n\nclass NFLDataset(InMemoryDataset):\n    def __init__(self, root, transform=None, pre_transform=None):\n        super(NFLDataset, self).__init__(root, transform, pre_transform)\n        self.data, self.slices = torch.load(self.processed_paths[0])\n\n    @property\n    def raw_file_names(self):\n        return []\n    @property\n    def processed_file_names(self):\n        return ['../NFL.dataset']\n\n    def download(self):\n        pass\n    \n    def process(self):\n        \n        data_list = []\n\n        # process by session_id\n        ##inhere\n        grouped = df_KR.groupby('kickerCollege')\n        ##inhere\n        for kickerCollege, group in tqdm(grouped):\n          ##inhere\n            sess_item_id = LabelEncoder().fit_transform(group.returnerCollege)\n            group = group.reset_index(drop=True)\n            group['sess_item_id'] = sess_item_id\n            ##inhere\n            node_features = group.loc[group.kickerCollege==kickerCollege,['sess_item_id','returnerCollege']].sort_values('sess_item_id').returnerCollege.drop_duplicates().values\n\n            node_features = torch.LongTensor(node_features).unsqueeze(1)\n            target_nodes = group.sess_item_id.values[1:]\n            source_nodes = group.sess_item_id.values[:-1]\n\n            edge_index = torch.tensor([source_nodes,\n                                   target_nodes], dtype=torch.long)\n            x = node_features\n\n            y = torch.FloatTensor([group.label.values[0]])\n\n            data = Data(x=x, edge_index=edge_index, y=y)\n            data_list.append(data)\n        \n        data, slices = self.collate(data_list)\n        torch.save((data, slices), self.processed_paths[0])","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:55:25.610734Z","iopub.execute_input":"2022-01-04T18:55:25.610992Z","iopub.status.idle":"2022-01-04T18:55:25.623461Z","shell.execute_reply.started":"2022-01-04T18:55:25.610960Z","shell.execute_reply":"2022-01-04T18:55:25.622824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = NFLDataset(root='../')","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:55:25.625584Z","iopub.execute_input":"2022-01-04T18:55:25.626095Z","iopub.status.idle":"2022-01-04T18:55:25.859862Z","shell.execute_reply.started":"2022-01-04T18:55:25.626034Z","shell.execute_reply":"2022-01-04T18:55:25.859088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = dataset.shuffle()\ntrain_dataset = dataset[:40]\nval_dataset = dataset[40:50]\ntest_dataset = dataset[50:]\nlen(train_dataset), len(val_dataset), len(test_dataset)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:55:25.860959Z","iopub.execute_input":"2022-01-04T18:55:25.861534Z","iopub.status.idle":"2022-01-04T18:55:25.873423Z","shell.execute_reply.started":"2022-01-04T18:55:25.861505Z","shell.execute_reply":"2022-01-04T18:55:25.872610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#from torch_geometric.data import DataLoader\nfrom torch_geometric.loader import DataLoader\nbatch_size= 2\ntrain_loader = DataLoader(train_dataset, batch_size=batch_size)\nval_loader = DataLoader(val_dataset, batch_size=batch_size)\ntest_loader = DataLoader(test_dataset, batch_size=batch_size)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:55:25.874939Z","iopub.execute_input":"2022-01-04T18:55:25.875386Z","iopub.status.idle":"2022-01-04T18:55:25.880556Z","shell.execute_reply.started":"2022-01-04T18:55:25.875352Z","shell.execute_reply":"2022-01-04T18:55:25.879842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dataset[20]","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:59:27.377817Z","iopub.execute_input":"2022-01-04T18:59:27.378645Z","iopub.status.idle":"2022-01-04T18:59:27.384910Z","shell.execute_reply.started":"2022-01-04T18:59:27.378584Z","shell.execute_reply":"2022-01-04T18:59:27.384025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_items = df_KR.returnerId.max()+1 \nnum_items ","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:59:32.660778Z","iopub.execute_input":"2022-01-04T18:59:32.661060Z","iopub.status.idle":"2022-01-04T18:59:32.670007Z","shell.execute_reply.started":"2022-01-04T18:59:32.661028Z","shell.execute_reply":"2022-01-04T18:59:32.668861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nfrom torch.nn import Sequential as Seq, Linear, ReLU\nfrom torch_geometric.nn import MessagePassing\nfrom torch_geometric.utils import remove_self_loops, add_self_loops\nclass SAGEConv(MessagePassing):\n    def __init__(self, in_channels, out_channels):\n        super(SAGEConv, self).__init__(aggr='max') #  \"Max\" aggregation.\n        self.lin = torch.nn.Linear(in_channels, out_channels)\n        self.act = torch.nn.ReLU()\n        self.update_lin = torch.nn.Linear(in_channels + out_channels, in_channels, bias=False)\n        self.update_act = torch.nn.ReLU()\n        \n    def forward(self, x, edge_index):\n        # x has shape [N, in_channels]\n        # edge_index has shape [2, E]\n        \n        \n        edge_index, _ = remove_self_loops(edge_index)\n        edge_index, _ = add_self_loops(edge_index, num_nodes=x.size(0))\n        \n        \n        return self.propagate(edge_index, size=(x.size(0), x.size(0)), x=x)\n\n    def message(self, x_j):\n        # x_j has shape [E, in_channels]\n\n        x_j = self.lin(x_j)\n        x_j = self.act(x_j)\n        \n        return x_j\n\n    def update(self, aggr_out, x):\n        # aggr_out has shape [N, out_channels]\n\n\n        new_embedding = torch.cat([aggr_out, x], dim=1)\n        \n        new_embedding = self.update_lin(new_embedding)\n        new_embedding = self.update_act(new_embedding)\n        \n        return new_embedding","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:59:34.588152Z","iopub.execute_input":"2022-01-04T18:59:34.588413Z","iopub.status.idle":"2022-01-04T18:59:34.653437Z","shell.execute_reply.started":"2022-01-04T18:59:34.588385Z","shell.execute_reply":"2022-01-04T18:59:34.652761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"embed_dim = 5\nfrom torch_geometric.nn import GraphConv, TopKPooling, GatedGraphConv\nfrom torch_geometric.nn import global_mean_pool as gap, global_max_pool as gmp\nimport torch.nn.functional as F\nclass Net(torch.nn.Module):\n    def __init__(self):\n        super(Net, self).__init__()\n\n        self.conv1 = SAGEConv(embed_dim, 5)\n        self.pool1 = TopKPooling(5, ratio=0.8)\n        self.conv2 = SAGEConv(5, 5)\n        self.pool2 = TopKPooling(5, ratio=0.8)\n        self.conv3 = SAGEConv(5, 5)\n        self.pool3 = TopKPooling(5, ratio=0.8)\n        ##inhere\n        self.item_embedding = torch.nn.Embedding(num_embeddings=df_KR.returnerCollege.max()+1, embedding_dim=embed_dim)\n        self.lin1 = torch.nn.Linear(10, 5)\n        self.lin2 = torch.nn.Linear(5, 3)\n        self.lin3 = torch.nn.Linear(3, 1)\n        self.bn1 = torch.nn.BatchNorm1d(5)\n        self.bn2 = torch.nn.BatchNorm1d(3)\n        self.act1 = torch.nn.ReLU()\n        self.act2 = torch.nn.ReLU()        \n  \n    def forward(self, data):\n        x, edge_index, batch = data.x, data.edge_index, data.batch\n        x = self.item_embedding(x)\n        x = x.squeeze(1)        \n\n        x = F.relu(self.conv1(x, edge_index))\n\n        x, edge_index, _, batch, _ , _ = self.pool1(x, edge_index, None, batch)\n        x1 = torch.cat([gmp(x, batch), gap(x, batch)], dim=1)\n\n        x = F.relu(self.conv2(x, edge_index))\n     \n        x, edge_index, _, batch, _ , _= self.pool2(x, edge_index, None, batch)\n        x2 = torch.cat([gmp(x, batch), gap(x, batch)], dim=1)\n\n        x = F.relu(self.conv3(x, edge_index))\n\n        x, edge_index, _, batch, _, _ = self.pool3(x, edge_index, None, batch)\n        x3 = torch.cat([gmp(x, batch), gap(x, batch)], dim=1)\n\n        x = x1 + x2 + x3\n\n        x = self.lin1(x)\n        x = self.act1(x)\n        x = self.lin2(x)\n        x = self.act2(x)      \n        x = F.dropout(x, p=0.5, training=self.training)\n\n        x = torch.sigmoid(self.lin3(x)).squeeze(1)\n\n        return x","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:59:38.448801Z","iopub.execute_input":"2022-01-04T18:59:38.449513Z","iopub.status.idle":"2022-01-04T18:59:38.467300Z","shell.execute_reply.started":"2022-01-04T18:59:38.449480Z","shell.execute_reply":"2022-01-04T18:59:38.466301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install GPUtil","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:59:45.266469Z","iopub.execute_input":"2022-01-04T18:59:45.267206Z","iopub.status.idle":"2022-01-04T18:59:54.265372Z","shell.execute_reply.started":"2022-01-04T18:59:45.267169Z","shell.execute_reply":"2022-01-04T18:59:54.264500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nfrom GPUtil import showUtilization as gpu_usage\nfrom numba import cuda\n\ndef free_gpu_cache():\n    print(\"Initial GPU Usage\")\n    gpu_usage()                             \n\n    torch.cuda.empty_cache()\n\n    cuda.select_device(0)\n    cuda.close()\n    cuda.select_device(0)\n\n    print(\"GPU Usage after emptying the cache\")\n    gpu_usage()\n\nfree_gpu_cache()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:59:54.268311Z","iopub.execute_input":"2022-01-04T18:59:54.268973Z","iopub.status.idle":"2022-01-04T18:59:55.674023Z","shell.execute_reply.started":"2022-01-04T18:59:54.268930Z","shell.execute_reply":"2022-01-04T18:59:55.673137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"device = torch.device('cuda')\nmodel = Net().to(device)\noptimizer = torch.optim.Adam(model.parameters(), lr=0.005)\ncrit = torch.nn.BCELoss()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T18:59:58.640205Z","iopub.execute_input":"2022-01-04T18:59:58.641161Z","iopub.status.idle":"2022-01-04T19:00:01.745140Z","shell.execute_reply.started":"2022-01-04T18:59:58.641106Z","shell.execute_reply":"2022-01-04T19:00:01.744241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def train():\n    model.train()\n\n    loss_all = 0\n    for data in train_loader:\n        data = data.to(device)\n        optimizer.zero_grad()\n        output = model(data)\n        label = data.y.to(device)\n        loss = crit(output, label)\n        loss.backward()\n        loss_all += data.num_graphs * loss.item()\n        optimizer.step()\n    return loss_all / len(train_dataset)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T19:00:02.457847Z","iopub.execute_input":"2022-01-04T19:00:02.458430Z","iopub.status.idle":"2022-01-04T19:00:02.466015Z","shell.execute_reply.started":"2022-01-04T19:00:02.458392Z","shell.execute_reply":"2022-01-04T19:00:02.465226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import roc_auc_score\ndef evaluate(loader):\n    model.eval()\n\n    predictions = []\n    labels = []\n\n    with torch.no_grad():\n        for data in loader:\n\n            data = data.to(device)\n            pred = model(data).detach().cpu().numpy()\n\n            label = data.y.detach().cpu().numpy()\n            predictions.append(pred)\n            labels.append(label)\n\n    predictions = np.hstack(predictions)\n    labels = np.hstack(labels)\n    \n    return roc_auc_score(labels, predictions)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T19:00:05.714074Z","iopub.execute_input":"2022-01-04T19:00:05.714349Z","iopub.status.idle":"2022-01-04T19:00:05.723499Z","shell.execute_reply.started":"2022-01-04T19:00:05.714318Z","shell.execute_reply":"2022-01-04T19:00:05.722780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for epoch in range(10):\n    loss = train()\n    train_acc = evaluate(train_loader)\n    #val_acc = evaluate(val_loader)    \n   # test_acc = evaluate(test_loader)\n   # print('Epoch: {:03d}, Loss: {:.5f}, Train Auc: {:.5f}, Val Auc: {:.5f}, Test Auc: {:.5f}'.\n   #       format(epoch, loss, train_acc, val_acc, test_acc))\n    print('Epoch: {:03d}, Loss: {:.5f}, Train Auc: {:.5f}'.\n          format(epoch, loss, train_acc))","metadata":{"execution":{"iopub.status.busy":"2022-01-04T19:01:36.720759Z","iopub.execute_input":"2022-01-04T19:01:36.721539Z","iopub.status.idle":"2022-01-04T19:01:40.737462Z","shell.execute_reply.started":"2022-01-04T19:01:36.721503Z","shell.execute_reply":"2022-01-04T19:01:40.736636Z"},"trusted":true},"execution_count":null,"outputs":[]}]}