{"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":"## train data","metadata":{}},{"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 plotly.express as px\nimport matplotlib.pyplot as plt\nfrom statsmodels.graphics.mosaicplot import mosaic\nimport cv2\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-12T20:49:48.621419Z","iopub.execute_input":"2022-08-12T20:49:48.621837Z","iopub.status.idle":"2022-08-12T20:49:48.636689Z","shell.execute_reply.started":"2022-08-12T20:49:48.621799Z","shell.execute_reply":"2022-08-12T20:49:48.635753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('../input/dfl-bundesliga-data-shootout/train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:48.644782Z","iopub.execute_input":"2022-08-12T20:49:48.645416Z","iopub.status.idle":"2022-08-12T20:49:48.659905Z","shell.execute_reply.started":"2022-08-12T20:49:48.645384Z","shell.execute_reply":"2022-08-12T20:49:48.659036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:48.661615Z","iopub.execute_input":"2022-08-12T20:49:48.662176Z","iopub.status.idle":"2022-08-12T20:49:48.673351Z","shell.execute_reply.started":"2022-08-12T20:49:48.662142Z","shell.execute_reply":"2022-08-12T20:49:48.672490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.tail()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:49.580197Z","iopub.execute_input":"2022-08-12T20:49:49.581078Z","iopub.status.idle":"2022-08-12T20:49:49.591532Z","shell.execute_reply.started":"2022-08-12T20:49:49.581045Z","shell.execute_reply":"2022-08-12T20:49:49.590711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:49.609610Z","iopub.execute_input":"2022-08-12T20:49:49.610240Z","iopub.status.idle":"2022-08-12T20:49:49.623861Z","shell.execute_reply.started":"2022-08-12T20:49:49.610197Z","shell.execute_reply":"2022-08-12T20:49:49.622674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:49.625728Z","iopub.execute_input":"2022-08-12T20:49:49.626485Z","iopub.status.idle":"2022-08-12T20:49:49.636099Z","shell.execute_reply.started":"2022-08-12T20:49:49.626456Z","shell.execute_reply":"2022-08-12T20:49:49.635186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=train['video_id'].value_counts()\nprint(x)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:49.683081Z","iopub.execute_input":"2022-08-12T20:49:49.683454Z","iopub.status.idle":"2022-08-12T20:49:49.690346Z","shell.execute_reply.started":"2022-08-12T20:49:49.683425Z","shell.execute_reply":"2022-08-12T20:49:49.689373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig_0 = px.bar(train['video_id'].value_counts(),text_auto='.2s', orientation='h',\\\n               title='Number of events for each video')\nfig_0.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:49.707764Z","iopub.execute_input":"2022-08-12T20:49:49.708402Z","iopub.status.idle":"2022-08-12T20:49:49.768282Z","shell.execute_reply.started":"2022-08-12T20:49:49.708372Z","shell.execute_reply":"2022-08-12T20:49:49.767364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig_1 = px.bar(train,x='event',y='video_id',\n             color='event_attributes',title = 'Event and Event attributes types')\nfig_1.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:49.769974Z","iopub.execute_input":"2022-08-12T20:49:49.771026Z","iopub.status.idle":"2022-08-12T20:49:49.898864Z","shell.execute_reply.started":"2022-08-12T20:49:49.770983Z","shell.execute_reply":"2022-08-12T20:49:49.897872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# code refrence : https://www.kaggle.com/code/gbalachandhiran/dfl-bundesliga-eda\nCrosstable = pd.crosstab(train['event'], train['event_attributes'])\nCrosstable.style.background_gradient(cmap='Greens')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:50.737622Z","iopub.execute_input":"2022-08-12T20:49:50.738027Z","iopub.status.idle":"2022-08-12T20:49:50.777676Z","shell.execute_reply.started":"2022-08-12T20:49:50.737984Z","shell.execute_reply":"2022-08-12T20:49:50.777017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig_2 = px.bar(train,x='video_id',y='event',\n             color='event',title = 'Event types throw videos')\nfig_2.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:50.778837Z","iopub.execute_input":"2022-08-12T20:49:50.779615Z","iopub.status.idle":"2022-08-12T20:49:50.921246Z","shell.execute_reply.started":"2022-08-12T20:49:50.779586Z","shell.execute_reply":"2022-08-12T20:49:50.920363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Look at the play event","metadata":{}},{"cell_type":"markdown","source":"The competition focused on challenge , throwin and play events so we w'll focus on them","metadata":{}},{"cell_type":"code","source":"fig_3 = px.bar(train.query('event not in [\"start\",\"end\"]')\\\n    .groupby('video_id')['event'].value_counts().unstack(),orientation='h')\nfig_3.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:50.922816Z","iopub.execute_input":"2022-08-12T20:49:50.923737Z","iopub.status.idle":"2022-08-12T20:49:50.997147Z","shell.execute_reply.started":"2022-08-12T20:49:50.923678Z","shell.execute_reply":"2022-08-12T20:49:50.996242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# look at a data for one video\ntrain.query('video_id ==\"1606b0e6_0\"& event not in [\"start\",\"end\"]')\\\n.groupby('event_attributes')['event'].value_counts().unstack()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:50.998363Z","iopub.execute_input":"2022-08-12T20:49:50.999073Z","iopub.status.idle":"2022-08-12T20:49:51.020147Z","shell.execute_reply.started":"2022-08-12T20:49:50.999036Z","shell.execute_reply":"2022-08-12T20:49:51.019152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Sample of submission","metadata":{}},{"cell_type":"code","source":"sub = pd.read_csv('../input/dfl-bundesliga-data-shootout/sample_submission.csv')\nsub.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:51.022491Z","iopub.execute_input":"2022-08-12T20:49:51.023557Z","iopub.status.idle":"2022-08-12T20:49:51.036622Z","shell.execute_reply.started":"2022-08-12T20:49:51.023518Z","shell.execute_reply":"2022-08-12T20:49:51.035919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig_4 = px.bar(sub,x='event',y='video_id',color = 'event',title = 'Event types and the score')\nfig_4.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:51.037766Z","iopub.execute_input":"2022-08-12T20:49:51.038308Z","iopub.status.idle":"2022-08-12T20:49:51.096389Z","shell.execute_reply.started":"2022-08-12T20:49:51.038281Z","shell.execute_reply":"2022-08-12T20:49:51.095491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig_5 = px.bar(sub,x='video_id',y='score',\n             color='event',title = 'Score and events at each video')\nfig_5.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:51.097753Z","iopub.execute_input":"2022-08-12T20:49:51.098290Z","iopub.status.idle":"2022-08-12T20:49:51.158864Z","shell.execute_reply.started":"2022-08-12T20:49:51.098255Z","shell.execute_reply":"2022-08-12T20:49:51.158018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Look at a video and display it's data","metadata":{}},{"cell_type":"code","source":"# look at a data for one video\nsub.query('video_id ==\"019d5b34_0\"& event not in [\"start\",\"end\"]')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:51.159885Z","iopub.execute_input":"2022-08-12T20:49:51.160287Z","iopub.status.idle":"2022-08-12T20:49:51.174259Z","shell.execute_reply.started":"2022-08-12T20:49:51.160262Z","shell.execute_reply":"2022-08-12T20:49:51.173288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Baris Dincer https://www.kaggle.com/brsdincer/human-evolution-process-dcgan/notebook\ndef video_list(Video_Path):\n    Video_IMG_List = []\n\n    Video_Cap = cv2.VideoCapture(Video_Path)\n\n\n    while Video_Cap.isOpened():\n\n\n        ret,frame = Video_Cap.read()\n\n        if ret != True:\n            break\n\n        if Video_Cap.isOpened():\n            Transformation_IMG = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)\n            Resize_IMG = cv2.resize(Transformation_IMG,(180,180))\n            Video_IMG_List.append(Resize_IMG)\n\n\n    Video_Cap.release()\n    return Video_IMG_List","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:51.725603Z","iopub.execute_input":"2022-08-12T20:49:51.726553Z","iopub.status.idle":"2022-08-12T20:49:51.733266Z","shell.execute_reply.started":"2022-08-12T20:49:51.726516Z","shell.execute_reply":"2022-08-12T20:49:51.732636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"video_file = '../input/dfl-bundesliga-data-shootout/test/019d5b34_0.mp4'\nvideo_one_list = video_list(video_file)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:51.752203Z","iopub.execute_input":"2022-08-12T20:49:51.752802Z","iopub.status.idle":"2022-08-12T20:49:56.047354Z","shell.execute_reply.started":"2022-08-12T20:49:51.752763Z","shell.execute_reply":"2022-08-12T20:49:56.046597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(np.shape(np.asarray(video_one_list)))","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:56.048902Z","iopub.execute_input":"2022-08-12T20:49:56.049343Z","iopub.status.idle":"2022-08-12T20:49:56.229364Z","shell.execute_reply.started":"2022-08-12T20:49:56.049315Z","shell.execute_reply":"2022-08-12T20:49:56.228741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"figure = plt.figure(figsize=(8,8))\n\nPick_IMG = video_one_list[100]\nplt.xlabel(Pick_IMG.shape)\nplt.ylabel(Pick_IMG.size)\nplt.imshow(Pick_IMG);","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:56.230251Z","iopub.execute_input":"2022-08-12T20:49:56.230966Z","iopub.status.idle":"2022-08-12T20:49:56.514068Z","shell.execute_reply.started":"2022-08-12T20:49:56.230940Z","shell.execute_reply":"2022-08-12T20:49:56.513419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig,axis = plt.subplots(4,4,figsize=(10,10))\n\nfor i,ax in enumerate(axis.flat):\n    \n    IMG_From_List = video_one_list[i]\n    ax.set_xlabel(IMG_From_List.shape)\n    ax.imshow(IMG_From_List)\n    \nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:56.514918Z","iopub.execute_input":"2022-08-12T20:49:56.515359Z","iopub.status.idle":"2022-08-12T20:49:58.149709Z","shell.execute_reply.started":"2022-08-12T20:49:56.515334Z","shell.execute_reply":"2022-08-12T20:49:58.148745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Get image from frame","metadata":{}},{"cell_type":"code","source":"# reference : https://www.kaggle.com/coldfir3/eda-helmet-keypoint-tracking-data-comparison\nimport PIL.Image\ndef get_frame_from_video(video_path, frame):\n    video_path = video_path\n    frame = frame - 1\n    \n    !ffmpeg \\\n        -hide_banner \\\n        -loglevel fatal \\\n        -nostats \\\n        -i $video_path -vf \"select=eq(n\\,$frame)\" -vframes 1 frame.jpg\n    \n    img = PIL.Image.open('frame.jpg')#StackOverflow https://stackoverflow.com/questions/10748822/img-image-openfp-attributeerror-class-image-has-no-attribute-open\n    os.remove('frame.jpg') \n    return img","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:58.152197Z","iopub.execute_input":"2022-08-12T20:49:58.152886Z","iopub.status.idle":"2022-08-12T20:49:58.161454Z","shell.execute_reply.started":"2022-08-12T20:49:58.152857Z","shell.execute_reply":"2022-08-12T20:49:58.160338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"get_frame_from_video('../input/dfl-bundesliga-data-shootout/test/019d5b34_0.mp4', 110)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:58.162837Z","iopub.execute_input":"2022-08-12T20:49:58.163476Z","iopub.status.idle":"2022-08-12T20:49:59.498189Z","shell.execute_reply.started":"2022-08-12T20:49:58.163445Z","shell.execute_reply":"2022-08-12T20:49:59.496986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Ducky https://www.kaggle.com/code/illgamhoduck/nfl-starter-eda\n\nfrom IPython.display import Video, display\n\ndef video(video_path, ratio=0.7):\n    nfl_video = Video(video_path,\n                      embed=True,\n                      height=int(720 * ratio),\n                      width=int(1280 * ratio))\n    return nfl_video\n    \nvideo('../input/dfl-bundesliga-data-shootout/test/019d5b34_0.mp4')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T20:49:59.499608Z","iopub.execute_input":"2022-08-12T20:49:59.499932Z","iopub.status.idle":"2022-08-12T20:49:59.908738Z","shell.execute_reply.started":"2022-08-12T20:49:59.499905Z","shell.execute_reply":"2022-08-12T20:49:59.907930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}