{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\n##import numpy as np # linear algebra\n##import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\n##import os\n##for 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\n","metadata":{"execution":{"iopub.status.busy":"2023-01-30T19:50:53.087644Z","iopub.execute_input":"2023-01-30T19:50:53.088143Z","iopub.status.idle":"2023-01-30T19:50:53.094225Z","shell.execute_reply.started":"2023-01-30T19:50:53.088104Z","shell.execute_reply":"2023-01-30T19:50:53.092812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport gc\nimport subprocess\n\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as patches\nfrom IPython.display import Video, display\nfrom sklearn.model_selection import GroupKFold\nfrom sklearn.metrics import (\n    roc_auc_score,\n    matthews_corrcoef,\n)\n\nimport seaborn as sns\n%matplotlib inline\n\nimport warnings\nwarnings.simplefilter(action='ignore', category=FutureWarning)","metadata":{"execution":{"iopub.status.busy":"2023-01-30T19:50:58.843759Z","iopub.execute_input":"2023-01-30T19:50:58.844146Z","iopub.status.idle":"2023-01-30T19:50:58.854389Z","shell.execute_reply.started":"2023-01-30T19:50:58.844116Z","shell.execute_reply":"2023-01-30T19:50:58.853343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ==============================\n# read data\n# ==============================\n\nTEhelmets = pd.read_csv('/kaggle/input/nfl-player-contact-detection/test_baseline_helmets.csv')\nTRhelmets = pd.read_csv('/kaggle/input/nfl-player-contact-detection/train_baseline_helmets.csv')\nsub = pd.read_csv('/kaggle/input/nfl-player-contact-detection/sample_submission.csv')\nTRtracking = pd.read_csv('/kaggle/input/nfl-player-contact-detection/train_player_tracking.csv')\nTEtracking = pd.read_csv('/kaggle/input/nfl-player-contact-detection/test_player_tracking.csv')\nTRvideoMeta = pd.read_csv('/kaggle/input/nfl-player-contact-detection/train_video_metadata.csv')\ntrainlabels = pd.read_csv('/kaggle/input/nfl-player-contact-detection/train_labels.csv')","metadata":{"execution":{"iopub.status.busy":"2023-01-30T20:10:26.059440Z","iopub.execute_input":"2023-01-30T20:10:26.059855Z","iopub.status.idle":"2023-01-30T20:10:40.181014Z","shell.execute_reply.started":"2023-01-30T20:10:26.059818Z","shell.execute_reply":"2023-01-30T20:10:40.179707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**1. Submission Dataset**","metadata":{}},{"cell_type":"code","source":"print(sub.columns) \nprint('')\n\n# checking for missing values in content_df dataframe\nmissing_values = sub.isnull().sum()\n# Drop content_df rows with missing values\nsub = sub.dropna()\nprint(missing_values)\nprint('')\n# Print the data types of the content dataframe\nprint(f'Submission DataFrame Data Types: \\n{sub.dtypes}')\nprint('')\nprint(sub.shape) # (49588, 2)\nprint('')\nprint(sub[:7]) \nprint('')\nprint(sub['contact_id'].value_counts())\nprint('')\nprint(sub['contact'].value_counts()) # 0    49588","metadata":{"execution":{"iopub.status.busy":"2023-01-30T20:00:27.728508Z","iopub.execute_input":"2023-01-30T20:00:27.729426Z","iopub.status.idle":"2023-01-30T20:00:27.810586Z","shell.execute_reply.started":"2023-01-30T20:00:27.729383Z","shell.execute_reply":"2023-01-30T20:00:27.809223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Using just countplot to get the bars in the same order as \n# value_counts() output:\nsns.countplot(data=sub, x='contact', order=sub.contact.value_counts().index)","metadata":{"execution":{"iopub.status.busy":"2023-01-30T20:00:59.610826Z","iopub.execute_input":"2023-01-30T20:00:59.611206Z","iopub.status.idle":"2023-01-30T20:00:59.823053Z","shell.execute_reply.started":"2023-01-30T20:00:59.611178Z","shell.execute_reply":"2023-01-30T20:00:59.821834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**2. trainlabels Dataset**","metadata":{}},{"cell_type":"code","source":"print(trainlabels.columns) \nprint('')\n\n# checking for missing values in content_df dataframe\nmissing_values = trainlabels.isnull().sum()\nprint(missing_values)\nprint('')\n# Drop content_df rows with missing values\ntrainlabels = trainlabels.dropna()\n# checking for missing values in content_df dataframe\nmissing_values = trainlabels.isnull().sum()\nprint(missing_values)\nprint('')\n# Print the data types of the content dataframe\nprint(f'trainlabels DataFrame Data Types: \\n{trainlabels.dtypes}')\nprint('')\nprint(trainlabels.shape) # (4721618, 7)\nprint('')\nprint(trainlabels[:7])\nprint('')\n#print(trainlabels.columns)\nprint(trainlabels['step'].value_counts()) # 173\nprint('')\nprint(trainlabels['game_play'].value_counts()) # 240\nprint('')\nprint(trainlabels['datetime'].value_counts()) # 18666\nprint('')\nprint(trainlabels['contact_id'].value_counts()) # 4721618\nprint('')\nprint(trainlabels['contact'].value_counts())\nprint('')\nprint(trainlabels['nfl_player_id_1'].value_counts()) # 1687\nprint('')\nprint(trainlabels['nfl_player_id_2'].value_counts()) # 1646","metadata":{"execution":{"iopub.status.busy":"2023-01-30T20:10:49.606676Z","iopub.execute_input":"2023-01-30T20:10:49.607107Z","iopub.status.idle":"2023-01-30T20:10:59.292236Z","shell.execute_reply.started":"2023-01-30T20:10:49.607068Z","shell.execute_reply":"2023-01-30T20:10:59.291165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Now, merge DataFrames using the merge() −\nM1 = sub.merge(trainlabels, on = 'contact_id', how='left')\nM1 # 49588 rows × 8 columns","metadata":{"execution":{"iopub.status.busy":"2023-01-30T20:11:38.954562Z","iopub.execute_input":"2023-01-30T20:11:38.955768Z","iopub.status.idle":"2023-01-30T20:11:44.205633Z","shell.execute_reply.started":"2023-01-30T20:11:38.955720Z","shell.execute_reply":"2023-01-30T20:11:44.204353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Using just countplot to get the bars in the same order as \n# value_counts() output:\nsns.countplot(data=M1, x='contact_x', order=M1.contact_y.value_counts().index)","metadata":{"execution":{"iopub.status.busy":"2023-01-30T20:12:15.364540Z","iopub.execute_input":"2023-01-30T20:12:15.364942Z","iopub.status.idle":"2023-01-30T20:12:15.537110Z","shell.execute_reply.started":"2023-01-30T20:12:15.364909Z","shell.execute_reply":"2023-01-30T20:12:15.536367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SUBMISSION = pd.DataFrame()\nSUBMISSION['contact_id']=M1['contact_id'] \nSUBMISSION['contact']=M1['contact_x'] #results1\nSUBMISSION","metadata":{"execution":{"iopub.status.busy":"2023-01-30T20:12:58.142179Z","iopub.execute_input":"2023-01-30T20:12:58.142547Z","iopub.status.idle":"2023-01-30T20:12:58.164572Z","shell.execute_reply.started":"2023-01-30T20:12:58.142509Z","shell.execute_reply":"2023-01-30T20:12:58.163515Z"},"trusted":true},"execution_count":null,"outputs":[]}]}