{"nbformat_minor":4,"nbformat":4,"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"}},"cells":[{"cell_type":"code","source":"import numpy as np \nimport pandas as pd  \nfrom sklearn import tree, ensemble\n\n","metadata":{"editable":false,"papermill":{"duration":1.209955,"end_time":"2021-12-28T12:53:38.973712","exception":false,"start_time":"2021-12-28T12:53:37.763757","status":"completed"},"tags":[],"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2022-04-14T06:28:58.108948Z","iopub.execute_input":"2022-04-14T06:28:58.109240Z","iopub.status.idle":"2022-04-14T06:28:59.302332Z","shell.execute_reply.started":"2022-04-14T06:28:58.109207Z","shell.execute_reply":"2022-04-14T06:28:59.301507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Special teams strategy:\n\nKickoffs.\nPunts.\nField goals.\nKick and punt returns.\nDowning the ball.\n\nReference:\nAmerican football strategy. (25 September 2021, at 23:35 (UTC)). Wikipedia. https://en.wikipedia.org/wiki/American_football_strategy#Special_teams_strategy","metadata":{}},{"cell_type":"code","source":"# cvs = '../input/nfl-big-data-bowl-2022/plays.csv'\n\n\nDATA_PATH = '../input/nfl-big-data-bowl-2022/plays.csv'\n\ndf_plays = pd.read_csv(DATA_PATH)\n\ndf_plays.fillna(0).head(2)  \n ","metadata":{"execution":{"iopub.status.busy":"2022-04-14T06:28:59.304159Z","iopub.execute_input":"2022-04-14T06:28:59.304480Z","iopub.status.idle":"2022-04-14T06:28:59.473906Z","shell.execute_reply.started":"2022-04-14T06:28:59.304443Z","shell.execute_reply":"2022-04-14T06:28:59.472966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Tactic:\n\nI apply ¨count¨ function to generated a dataframe bolong to occurrences. Then with ¨concat¨ function i generate a serie, where the team, the special one strategy and the result are mixed. For example, PHI/Kickoff/Touchback.   \n\nStrategy:\n\nTak different kind of series and calculate the average. ","metadata":{}},{"cell_type":"markdown","source":"**To Quantify spacials team strategies i would apply the concept of goal average:    **\n\n\n> \n>     This parameter is required for multiclass/multilabel targets. If None, the scores for each class are returned. Otherwise, this determines the type of averaging performed on the data:\n> \n>     'binary':\n> \n>         Only report results for the class specified by pos_label. This is applicable only if targets (y_{true,pred}) are binary.\n>     'micro':\n> \n>         Calculate metrics globally by counting the total true positives, false negatives and false positives.\n>     'macro':\n> \n>         Calculate metrics for each label, and find their unweighted mean. This does not take label imbalance into account.\n>     'weighted':\n> \n>         Calculate metrics for each label, and find their average weighted by support (the number of true instances for each label). This alters ‘macro’ to account for label imbalance; it can result in an F-score that is not between precision and recall.\n>     'samples':\n> \n>         Calculate metrics for each instance, and find their average (only meaningful for multilabel classification where this differs from accuracy_score).*\n> \n© 2007 - 2021, scikit-learn developers (BSD License). sklearn.metrics.f1_score. scikit-learn.org. https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html [21/01/2022]","metadata":{}},{"cell_type":"code","source":"a = df_plays['possessionTeam'].str.count('PHI')\nb = df_plays['specialTeamsPlayType'].str.count('Kickoff')\nc = df_plays['specialTeamsResult'].str.count('Touchback')\ny_true = pd.concat([a,b,c])\ny_true.head()\n\na = df_plays['possessionTeam'].str.count('PHI')\nb = df_plays['specialTeamsPlayType'].str.count('Field Goal')\nc = df_plays['specialTeamsResult'].str.count('Kick Attempt Good')\ny_true1 = pd.concat([a,b,c])\ny_true1.head()\n\n\na = df_plays['possessionTeam'].str.count('PHI')\nb = df_plays['specialTeamsPlayType'].str.count('')\nc = df_plays['specialTeamsResult'].str.count('')\ny_pred  = pd.concat([a,b,c])\n\nfrom sklearn.metrics import f1_score\n \n\ndf = pd.DataFrame({'': [1,f1_score(y_true, y_pred, average='macro'),f1_score(y_true1, y_pred, average='macro')]},\n\n                  index=['PHI','Kickoff/Touchback','Field Goal/Kick Attempt Good'])\n\nplot = df.plot.pie(y='', figsize=(5, 5))\n\nf1_score(y_true, y_pred, average='macro'), f1_score(y_true1, y_pred, average='macro')\n\n \n\n\na = df_plays['possessionTeam'].str.count('BUF')\nb = df_plays['specialTeamsPlayType'].str.count('Punt')\nc = df_plays['specialTeamsResult'].str.count('Out of Bounds')\ny_true = pd.concat([a,b,c])\n \n\n\na = df_plays['possessionTeam'].str.count('PHI')\nb = df_plays['specialTeamsPlayType'].str.count('')\nc = df_plays['specialTeamsResult'].str.count('')\ny_pred  = pd.concat([a,b,c])\n \n\nfrom sklearn.metrics import f1_score\n\n\n\ndf = pd.DataFrame({'': [1,f1_score(y_true, y_pred, average='macro')]},\n\n                  index=['BUF', 'Punt/Out of Bounds'])\n\nplot = df.plot.pie(y='', figsize=(5, 5))\n\nf1_score(y_true, y_pred, average='macro')\n","metadata":{"execution":{"iopub.status.busy":"2022-04-14T06:28:59.475348Z","iopub.execute_input":"2022-04-14T06:28:59.475631Z","iopub.status.idle":"2022-04-14T06:29:00.426539Z","shell.execute_reply.started":"2022-04-14T06:28:59.475593Z","shell.execute_reply":"2022-04-14T06:29:00.425331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a = df_plays['possessionTeam'].str.count('ATL')\nb = df_plays['specialTeamsPlayType'].str.count('Punt')\nc = df_plays['specialTeamsResult'].str.count('')\ny_true = pd.concat([a,b,c])\n \n\n\na = df_plays['possessionTeam'].str.count('ATL')\nb = df_plays['specialTeamsPlayType'].str.count('')\nc = df_plays['specialTeamsResult'].str.count('')\ny_pred  = pd.concat([a,b,c])\n \n\nfrom sklearn.metrics import f1_score\n\n\n\ndf = pd.DataFrame({'': [1,f1_score(y_true, y_pred, average='macro')]},\n\n                  index=['ATL', 'Punt'])\n\nplot = df.plot.pie(y='', figsize=(5, 5))\n\nf1_score(y_true, y_pred, average='macro')\n","metadata":{"execution":{"iopub.status.busy":"2022-04-14T06:29:00.431196Z","iopub.execute_input":"2022-04-14T06:29:00.431590Z","iopub.status.idle":"2022-04-14T06:29:00.830936Z","shell.execute_reply.started":"2022-04-14T06:29:00.431528Z","shell.execute_reply":"2022-04-14T06:29:00.830081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"df_plays['possessionTeam'].str.count('ATL')","metadata":{"execution":{"iopub.status.busy":"2022-04-14T06:30:50.171344Z","iopub.execute_input":"2022-04-14T06:30:50.171728Z","iopub.status.idle":"2022-04-14T06:30:50.191642Z","shell.execute_reply.started":"2022-04-14T06:30:50.171690Z","shell.execute_reply":"2022-04-14T06:30:50.190751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plays['possessionTeam']. value_counts(), df_plays['specialTeamsPlayType']. value_counts(),df_plays['specialTeamsResult']. value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-04-14T06:37:02.955831Z","iopub.execute_input":"2022-04-14T06:37:02.956148Z","iopub.status.idle":"2022-04-14T06:37:02.969958Z","shell.execute_reply.started":"2022-04-14T06:37:02.956113Z","shell.execute_reply":"2022-04-14T06:37:02.969270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}