{"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":"#  Introductions\nDataset: kaggle competition dataset\n\n* We want to detect external contact experienced by players during an NFL football game. You will use video and player tracking data to identify moments with contact to help improve player safety.","metadata":{}},{"cell_type":"markdown","source":"# Importing relevant libraries","metadata":{}},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os  # allows us to run a command in the Python script\nimport plotly.express as px #visualizations with layout styling, interactivity, animations, and many chart .\nimport cv2 #allows you to perform image processing and computer vision tasks\nimport subprocess # used to run new codes and applications by creating new processes\nfrom IPython.display import Video, display #Create a video object given raw data or an URL.\n\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as patches\n%matplotlib inline\nplt.rcParams['figure.dpi'] = 150\n\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:33:06.403152Z","iopub.execute_input":"2022-12-12T16:33:06.404104Z","iopub.status.idle":"2022-12-12T16:33:09.212601Z","shell.execute_reply.started":"2022-12-12T16:33:06.403994Z","shell.execute_reply":"2022-12-12T16:33:09.210594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"_kg_hide-output":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-12-12T16:33:09.215595Z","iopub.execute_input":"2022-12-12T16:33:09.216091Z","iopub.status.idle":"2022-12-12T16:33:09.471968Z","shell.execute_reply.started":"2022-12-12T16:33:09.216041Z","shell.execute_reply":"2022-12-12T16:33:09.470089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Read the Datasets","metadata":{}},{"cell_type":"code","source":"nfl_trainbaseline = pd.read_csv(\"/kaggle/input/nfl-player-contact-detection/train_baseline_helmets.csv\")\nnfl_testbaseline = pd.read_csv(\"/kaggle/input/nfl-player-contact-detection/test_baseline_helmets.csv\")\nprint(\"Train and test baseline helmets data uploaded successfully!\")\n\nnfl_trainplayer=pd.read_csv (\"/kaggle/input/nfl-player-contact-detection/train_player_tracking.csv\")\nnfl_testplayer=pd.read_csv(\"/kaggle/input/nfl-player-contact-detection/test_player_tracking.csv\")\nprint(\"Train and test player tracking data uploaded successfully!\")\n\nnfl_trainlabels = pd.read_csv(\"/kaggle/input/nfl-player-contact-detection/train_labels.csv\")\nprint(\"Train labels data uploaded successfully!\")\n\nnfl_trainmetadata = pd.read_csv(\"/kaggle/input/nfl-player-contact-detection/train_video_metadata.csv\")\nnfl_testmetadata = pd.read_csv(\"/kaggle/input/nfl-player-contact-detection/test_video_metadata.csv\")\nprint(\"Train and test video metadata uploaded successfully!\")\n","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:33:09.481064Z","iopub.execute_input":"2022-12-12T16:33:09.482513Z","iopub.status.idle":"2022-12-12T16:33:33.217128Z","shell.execute_reply.started":"2022-12-12T16:33:09.482443Z","shell.execute_reply":"2022-12-12T16:33:33.216108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Explanatory Data Analysis","metadata":{}},{"cell_type":"code","source":"# Gives the first 5 rows of the data\nnfl_trainplayer.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:33:33.218434Z","iopub.execute_input":"2022-12-12T16:33:33.218888Z","iopub.status.idle":"2022-12-12T16:33:33.252803Z","shell.execute_reply.started":"2022-12-12T16:33:33.218855Z","shell.execute_reply":"2022-12-12T16:33:33.251488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Gives the last 5 rows of the data\nnfl_trainplayer.tail()","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:33:33.255828Z","iopub.execute_input":"2022-12-12T16:33:33.256189Z","iopub.status.idle":"2022-12-12T16:33:33.281055Z","shell.execute_reply.started":"2022-12-12T16:33:33.256156Z","shell.execute_reply":"2022-12-12T16:33:33.280030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nfl_trainplayer.info()","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:33:33.282599Z","iopub.execute_input":"2022-12-12T16:33:33.283853Z","iopub.status.idle":"2022-12-12T16:33:33.569756Z","shell.execute_reply.started":"2022-12-12T16:33:33.283805Z","shell.execute_reply":"2022-12-12T16:33:33.568343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# To get the data information\nnfl_testplayer.info()","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:33:33.571187Z","iopub.execute_input":"2022-12-12T16:33:33.571970Z","iopub.status.idle":"2022-12-12T16:33:33.590835Z","shell.execute_reply.started":"2022-12-12T16:33:33.571926Z","shell.execute_reply":"2022-12-12T16:33:33.589585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* Train player tracking dataset has total 17 columns and rangeindex: 14872 and shows column wise datatype info","metadata":{}},{"cell_type":"code","source":"# To show the the column index name\nnfl_trainplayer.columns","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:33:33.592284Z","iopub.execute_input":"2022-12-12T16:33:33.592718Z","iopub.status.idle":"2022-12-12T16:33:33.600399Z","shell.execute_reply.started":"2022-12-12T16:33:33.592676Z","shell.execute_reply":"2022-12-12T16:33:33.599317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# To get statistical information about data\nnfl_trainplayer.describe()","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:33:33.602312Z","iopub.execute_input":"2022-12-12T16:33:33.602711Z","iopub.status.idle":"2022-12-12T16:33:34.353169Z","shell.execute_reply.started":"2022-12-12T16:33:33.602679Z","shell.execute_reply":"2022-12-12T16:33:34.351856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#\"Shape of the Train player tracking:\"\nnfl_trainplayer.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:33:34.354688Z","iopub.execute_input":"2022-12-12T16:33:34.355142Z","iopub.status.idle":"2022-12-12T16:33:34.362619Z","shell.execute_reply.started":"2022-12-12T16:33:34.355108Z","shell.execute_reply":"2022-12-12T16:33:34.361287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#\"Shape of the Test player tracking:\"\nnfl_testplayer.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:33:34.364063Z","iopub.execute_input":"2022-12-12T16:33:34.364435Z","iopub.status.idle":"2022-12-12T16:33:34.374877Z","shell.execute_reply.started":"2022-12-12T16:33:34.364403Z","shell.execute_reply":"2022-12-12T16:33:34.374066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#To check null values\n\n# Heatmap is not neccessary in this data because there are no Nulls \n# I use it to check if there are Nulls in data and how frequently they occour\n\n# if there were Null we would see dashed lines for nulls\n# as there are none we see a solid color\nsns.heatmap(nfl_trainplayer.isnull())","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:33:34.376183Z","iopub.execute_input":"2022-12-12T16:33:34.377056Z","iopub.status.idle":"2022-12-12T16:34:05.552960Z","shell.execute_reply.started":"2022-12-12T16:33:34.377015Z","shell.execute_reply":"2022-12-12T16:34:05.552031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Conclusion: There is no null value in the data","metadata":{}},{"cell_type":"code","source":"nfl_trainmetadata.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:34:05.554169Z","iopub.execute_input":"2022-12-12T16:34:05.555104Z","iopub.status.idle":"2022-12-12T16:34:05.568635Z","shell.execute_reply.started":"2022-12-12T16:34:05.555068Z","shell.execute_reply":"2022-12-12T16:34:05.567482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Video_Metadata information\n\n* game_play: Unique game key & play id combination for the play.\n* game_key: the ID code for the game.\n* play_id: the ID code for the play.\n* view: The video view, either Sideline or Endzone\n* start_time: The timestamp of the video start.\n* end_time: The timestamp when the video ends.\n* snap_time: The timestamp when the play starts within the video. This is 5 seconds (300 frames) into the video.","metadata":{}},{"cell_type":"code","source":"# Gives the first 5 rows of the data\nnfl_trainlabels.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:34:05.571810Z","iopub.execute_input":"2022-12-12T16:34:05.572241Z","iopub.status.idle":"2022-12-12T16:34:05.588262Z","shell.execute_reply.started":"2022-12-12T16:34:05.572210Z","shell.execute_reply":"2022-12-12T16:34:05.586906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Player Tracker information\nEach player wears a sensor that allows us to locate them on the field; that information is reported in these two files.\n\n* game_play: Unique game key and play id combination for the play.\n* game_key: the ID code for the game.\n* play_id: the ID code for the play.\n* nfl_player_id: the player's ID code.\n* datetime: timestamp at 10 Hz.\n* step: timestep within play relative to the play start.\n* position: the football position of the player.\n* team: team of the player, either home or away.\n* jersey_number: Player jersey number\n* x_position: player position along the long axis of the field. See figure below.\n* y_position: player position along the short axis of the field. See figure below.\n* speed: speed in yards/second.\n* distance: distance traveled from prior time point, in yards.\n* orientation: orientation of player (deg).\n* direction: angle of player motion (deg).\n* event: game events like a snap, whistle, etc.\n* acceleration: magnitiude of the total acceleration in yards/second^2.\n* sa: Signed acceleration yards/second^2 in the direction the player is moving.","metadata":{}},{"cell_type":"code","source":"# Gives the first 5 rows of the data\nnfl_trainbaseline.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:34:05.589858Z","iopub.execute_input":"2022-12-12T16:34:05.590184Z","iopub.status.idle":"2022-12-12T16:34:05.607597Z","shell.execute_reply.started":"2022-12-12T16:34:05.590157Z","shell.execute_reply":"2022-12-12T16:34:05.606370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Baseline_helmets information\n* game_play: Unique game key and play id combination for the play.\n* game_key: the ID code for the game.\n* play_id: the ID code for the play.\n* view: The video view, either Sideline or Endzone\n* video: The filename of the associated video.\n* frame: The associated frame within the video.\n* nfl_player_id: The imperfect predicted player id.\n* player_label: The player label. A combination of V/H (home or visiting team) and the player jersey number.","metadata":{}},{"cell_type":"code","source":"# Define the video we'll process\nvideo_name = nfl_trainbaseline['video'][0]\nvideo_name","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:34:05.609920Z","iopub.execute_input":"2022-12-12T16:34:05.610820Z","iopub.status.idle":"2022-12-12T16:34:05.618573Z","shell.execute_reply.started":"2022-12-12T16:34:05.610774Z","shell.execute_reply":"2022-12-12T16:34:05.617464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define the path and then display the video using \nvideo_path = \"/kaggle/input/nfl-player-contact-detection/train/58168_003392_Endzone.mp4\"\ndisplay(Video(data=video_path, embed=True))\n","metadata":{"execution":{"iopub.status.busy":"2022-12-12T16:34:05.620224Z","iopub.execute_input":"2022-12-12T16:34:05.620691Z","iopub.status.idle":"2022-12-12T16:34:06.045284Z","shell.execute_reply.started":"2022-12-12T16:34:05.620650Z","shell.execute_reply":"2022-12-12T16:34:06.043672Z"},"trusted":true},"execution_count":null,"outputs":[]}]}