{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"markdown","source":"NFL Punt analytic for concussion prevention"},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","collapsed":true,"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":false},"cell_type":"markdown","source":"In 2018 season NFL implement rule change to kickoff to limit concussion in kickoff. In this kaggle challenge, participant are asked to suggest rule change for reduction of concussion in punt as well. First we would have a review on previous rule change and regulation to elinimate concussion. "},{"metadata":{"_uuid":"6fdc0fba6163a3ae153b3fe59334b67887acf8d0"},"cell_type":"markdown","source":"**1. Review on NFL concussion safety policy**\n\n"},{"metadata":{"_uuid":"a89831c51630c99d8260c5ea2bfd485fcee22b33"},"cell_type":"markdown","source":"**a. Concussion Protocol**\n\nConcussion protocol was developed by NFL to ensure concussed players are receiving aquadate medicial care.\n\nIf a player exhibate signs of concussion, coaches, players or other NFL officials can trigger concussion protocol and the player is immediately moved to sidelide for concussion assessment. \n\nIf the result is positive or uncertain, player will be examined by team physicians in the locker room. Player is cleared to play only if he passed all assessment\n\n![](https://www.playsmartplaysafe.com/wp-content/uploads/2018/06/checklist-june-2018-final1-791x1024.png)\n\n\nFor every NFL players who are diagnosed with a concussion, players need to go through a 5-step return-to-participation protocol and cleared by team physicians in order to resume contact practice and play in a game.\n\n![](https://www.playsmartplaysafe.com/wp-content/uploads/2017/07/nfl_returntoparticipationprotocol.png)\n\n\n"},{"metadata":{"trusted":true,"_uuid":"092d1eb80162216f1594a3ab1d57b906ba796e20"},"cell_type":"markdown","source":"**b. Equipment and technology**\n\nIn 2016, NFL pledged $60 millions fro  a five-year plan called the Engineering Roadmap to help a better understanding of biomechanics of head injuries. Here are a few examples on how new technology can help to promote a safer games:\n\n**Helmet testing**: Every year, NFL conduct laboratory research to evaluate which helmets best reduce head impact severity and the findings are shard to NFL teams and players. In 2018 season, 10 helmets are banned to use due to their performance.  \n![](https://www.playsmartplaysafe.com/wp-content/uploads/2016/05/helmet1-767x1024.png)\n\n**HeadHealthTECH Challenges**: NFL has held HeadHealthTECH Challenges annually to attract companies and universities for develop improved helmets and protective equipment. Six challenges has beed held with up to $1 million annual funding.\n\n**Electronic equipment**: NFL teams have access to sideline video monitors and able to review the cause the injury and design the best care for the player. Also, medical staff has instant access of player's electronic medical record as well as electronic tablets for concussion diagnosis and treatment.\n\n"},{"metadata":{"_uuid":"739fe323742f31ad6087ba8851d38fa8d76f3518"},"cell_type":"markdown","source":"**c. Rule Change**\n\n Since 2002, NFL has made 50 rules changes intended to eliminate potentially dangerous tactics and reduce the risk of injuries. Specifically in 2018 season:\n \n** Use of Helmet rule**:\n\nA 15-yards penalty if a player lowers his head to initiate and make contact with his helmet against an opponent. He might also be ejected from the game.\n\n** Kickoff rule change**\n\n* Kickoff team must have five players on each side of the ball.\n\n* Eight players of the receiving team must be lined up in the 15-yard “setup zone”\n\n* No wedge blocks (shoulder-to-shoulder allignment) are permitted\n\n* No player on either the receiving or kicking team may block within the 15-yard area, or 10-yard for onside-kick\n\n* The ball is dead if it is not touched by the receiving team and touches the ground in the end zone (touchback)"},{"metadata":{"_uuid":"b63620233f5819d4db1d1f52be63bf789d9b04cb"},"cell_type":"markdown","source":"**2. Overview of data**"},{"metadata":{"_uuid":"35b36743973a1f7f2bfcc6b1df2a398131f30414"},"cell_type":"markdown","source":"Here is the overview of concussion data for punting play in 16-17 NFL season"},{"metadata":{"trusted":true,"_uuid":"67a0f808ce84050f55f229c0a6911bd698f06114","_kg_hide-input":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom IPython.display import HTML\nimport math\nplt.style.use('seaborn')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"85c7a07b27b3cec0cc8a5b153d5b52e69960c152","_kg_hide-input":true},"cell_type":"code","source":"video_review = pd.read_csv('../input/video_review.csv')\nvideo_review.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"94b89b16031818b39fba162e990f7054f8a024f8"},"cell_type":"code","source":"player_role_data = pd.read_csv('../input/play_player_role_data.csv')\nplayer_role_data.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"969dee8b11692f1beae04c9c11fc5cf096cc95a4","scrolled":true},"cell_type":"code","source":"play_information_data = pd.read_csv('../input/play_information.csv')\nplay_information_data.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b2e794e8fc8ea048bea10a0c0605cd840c6c26a7"},"cell_type":"code","source":"video_footage_injury_data = pd.read_csv('../input/video_footage-injury.csv')\nvideo_footage_injury_data.head()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"2255652fe9f6a9026aa78fe4c0addde539aa0748"},"cell_type":"markdown","source":"First we look at how much concussion happens during punt play in 16-17 season"},{"metadata":{"trusted":true,"scrolled":false,"_uuid":"786b21294d11ed3fa374478896fbbb2f7bf114af"},"cell_type":"code","source":"len(video_review)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"de2637c0a7e489cd405d84af71da2208bb1a91c2"},"cell_type":"markdown","source":"In 16-17 season punt play account for about 6.4% of total plays. From [nfl concussion data](https://www.playsmartplaysafe.com/newsroom/reports/2017-injury-data/) there are 452 concussions happens during 16-17 NFL game and therefore punt plays account for 8.2% of total concussion. It means that punt play generally has cause a slightly higher chance for concussion to happens. Next we look at the split of concussion data."},{"metadata":{"trusted":true,"_uuid":"14db90018a2ec4ebd2196ff4fe3f8dc494c8708f"},"cell_type":"code","source":"pd.value_counts(video_footage_injury_data['Type']).plot.bar()\nplt.title('Concussed play season type')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"833ee4d2ab168fc5aff6c1de1a770f7fdfbb451a"},"cell_type":"code","source":"pd.value_counts(video_footage_injury_data['season']).plot.bar()\nplt.title('Concussed play season year')\nplt.yticks(np.arange(25, step = 5))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2fa569dabcc585ed46a95b9b046999dd674819d4"},"cell_type":"code","source":"pd.value_counts(video_review['Player_Activity_Derived']).plot.bar()\nplt.title('Concussed player action')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"250178800b5eeabd4c4d47e40850c310d84f011a"},"cell_type":"code","source":"pd.value_counts(video_review['Primary_Partner_Activity_Derived']).plot.bar()\nplt.title('Concussion partner action')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6ae9694463381012fdbb918f7972d3ec161c1491"},"cell_type":"code","source":"pd.value_counts(video_review['Primary_Impact_Type']).plot.bar()\nplt.title('Impact position')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"229d31642194fd428a6f3aad17727aa9092e3cc4"},"cell_type":"code","source":"pd.value_counts(video_review['Friendly_Fire']).plot.bar()\nplt.title('Friendly fire?')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8a22b1f65722afbb5d26b38548cf81a0dfd18d20"},"cell_type":"markdown","source":"Next step we merge concussion data with play information and player role data"},{"metadata":{"trusted":true,"_uuid":"3faea74edc9ae229aa06ad51f011d0126a9c5bc4","scrolled":true},"cell_type":"code","source":"merged_data = pd.merge(video_review,play_information_data)\nmerged_data = pd.merge(merged_data,player_role_data)\nmerged_data.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"489005732c3e8fff769112fd9d303b4b66ba8156","scrolled":true},"cell_type":"code","source":"receiving_position = ['PR', 'PFB', 'VR', 'PDR1', 'PDL2']\n\nreceive_data = merged_data[merged_data.Role.isin(receiving_position)]\npd.value_counts(receive_data['Role']).plot.bar()\nplt.title('Concussed data by receiving team position')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"93be55f60f4ada9a1458e8f44f2c06c3033c416f","scrolled":false},"cell_type":"code","source":"punt_data = merged_data[~merged_data.Role.isin(receiving_position)]\npd.value_counts(punt_data['Role']).plot.bar()\nplt.yticks(np.arange(5))\nplt.title('Concussed data by punting team position')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"2687823e1b31cf8f2392124c6ca0ebaf2a6ce52c"},"cell_type":"markdown","source":"We can see that the risk of concussion of punting team has 7 times more than non-returner of receiving team."},{"metadata":{"trusted":true,"_uuid":"453e0893eb91de4920f50052dbce41b2260fe969"},"cell_type":"code","source":"punt_data['Concussed_position'] = 'kicking'\nreceive_data['Concussed_position'] = 'receiving'\npd.value_counts(pd.merge(receive_data,punt_data,how='outer')['Concussed_position']).plot.bar()\nplt.title('Concussed count by team split')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9fdaabd1322bb7be0ea66aa0c3973aae05662eee"},"cell_type":"code","source":"def return_yardline_from_string(pos_team,yardline_string):\n    \n    if (pos_team in yardline_string): #opponent yardline\n        yardline = 100 - float(yardline_string.split(' ')[1])\n    else:\n        yardline = float(yardline_string.split(' ')[1])\n        \n    return yardline    ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9c5238f3839c19268e3e9a5fcedd3534a5d74d58"},"cell_type":"code","source":"#merging all data using pivot table\ntable = pd.pivot_table(player_role_data,index=['GameKey', 'PlayID'],columns=['Role'], aggfunc=lambda x: len(x.unique()))['GSISID'].fillna(0) \n\ntable.reset_index(inplace=True)\n\nall_punt_data = pd.merge(table,play_information_data)\nall_punt_data = pd.merge(all_punt_data,video_review,how='outer')\n\npunt_yards_list = []\nadjust_yardline_list = []\nreturned_list = []\nreturn_yards_list = [] \nfair_catch_list = [] \nfor i,yards in enumerate(all_punt_data.PlayDescription.str.split('punts ').str[1].str[:2]):\n    try:\n        if('No Play' in all_punt_data['PlayDescription'][i] or 'Direct snap' in all_punt_data['PlayDescription'][i] or 'pass' in all_punt_data['PlayDescription'][i] or 'FUMBLE' in all_punt_data['PlayDescription'][i]):\n            punt_yards_list.append(np.nan)\n        else:\n            punt_yards_list.append(float(yards))\n    except ValueError:\n        punt_yards_list.append(np.nan)\n\n    if(all_punt_data['Poss_Team'][i] in all_punt_data['YardLine'][i]):\n        adjust_yardline_list.append(float(all_punt_data['YardLine'][i].split(' ')[1]))\n    else:\n        adjust_yardline_list.append(100-float(all_punt_data['YardLine'][i].split(' ')[1]))\n    if(' for ' in all_punt_data['PlayDescription'][i]): #returned kick\n        returned_list.append(1)\n    else:\n        returned_list.append(0)\n    if('fair catch' in all_punt_data['PlayDescription'][i]):\n        fair_catch_list.append(1)\n    else:\n        fair_catch_list.append(0)\n        \nfor i,yards in enumerate(all_punt_data.PlayDescription.str.split(' for ').str[1].str[:2]):        \n    try:\n        if('No Play' in all_punt_data['PlayDescription'][i] or 'fair catch' in all_punt_data['PlayDescription'][i] or 'Direct snap' in all_punt_data['PlayDescription'][i] or 'pass' in all_punt_data['PlayDescription'][i]):\n            return_yards_list.append(np.nan)\n        elif('MUFFS' in all_punt_data['PlayDescription'][i]):\n            return_yards_list.append(0)\n        elif(str(yards) == 'no'):\n            return_yards_list.append(0)\n        elif('PENALTY' in all_punt_data['PlayDescription'][i]):\n            return_yards_list.append(float(yards))\n#             if(all_punt_data['PlayDescription'][i].split('PENALTY on ')[1][:3] == all_punt_data['Poss_Team'][i]): #kicking team penalty\n#                 return_yards_list.append(float(yards))\n#             elif('TOUCHDOWN.' in all_punt_data['PlayDescription'][i]): #penalty after touchdown    \n#                 return_yards_list.append(float(yards))\n#             else:\n#                 return_end_yardline = return_yardline_from_string(all_punt_data['Poss_Team'][i],all_punt_data['PlayDescription'][i].split('to ')[1][:6])           \n#                 if(float(all_punt_data['PlayDescription'][i].split('enforced at ')[1][:2]) != 50):\n#                     penalty_yardline = return_yardline_from_string(all_punt_data['Poss_Team'][i],all_punt_data['PlayDescription'][i].split('enforced at ')[1][:6])\n#                 else:\n#                     penalty_yardline = 50\n#                 return_yards_list.append(return_end_yardline - penalty_yardline)\n                \n        else:    \n            return_yards_list.append(float(yards))\n    except ValueError:    \n        return_yards_list.append(np.nan)       \nall_punt_data['punt_yards'] = punt_yards_list\nall_punt_data['adjust_yardline'] = adjust_yardline_list\nall_punt_data['returned'] = returned_list\nall_punt_data['concussed'] = all_punt_data.GSISID.notnull().astype(int)\nall_punt_data['return_yards'] = return_yards_list\nall_punt_data['fair_catch'] = fair_catch_list\nall_punt_data['blocked'] = (all_punt_data.PlayDescription.str.contains('BLOCKED') == True | (all_punt_data.punt_yards <= 10)).astype(int)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"all_punt_data.to_csv('punt_play_data.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"321e101266f33d0e10430d92213caf013b5fd26f"},"cell_type":"code","source":"concussed_split = all_punt_data.groupby(['returned'])['concussed'].mean()\n\nprint(\"Non-return punt concussed percentage = %1.1f%%\" % (100*concussed_split[0]))\nprint(\"Returned punt concussed percentage = %1.1f%%\" % (100*concussed_split[1]))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2dc5a75120272fd66b0adf73aa522b0ef309ef94"},"cell_type":"code","source":"pd.value_counts(all_punt_data[all_punt_data['concussed'] == 1]['returned']).plot.bar()\nplt.xticks([0,1], ('Punt return', 'Others'))\nplt.title('Concussion number by punt outcome')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6358f394c1cafdd60b246e64035f296175a45dd8"},"cell_type":"markdown","source":"We can see that concussed percentage is way up for returned punt. Similar to kickoff rule change, one of the main idea of suggesting a rule change for punting is to motivate return for more fair catches but without eliminate punt return."},{"metadata":{"_uuid":"95bb3502c0da87ff1f11e9d6d07989a42ce03451"},"cell_type":"markdown","source":"**3. Proposed rule changes**"},{"metadata":{"trusted":true,"_uuid":"77c5cc46f5fbba832f87bfd2830d34fe518ac4ab"},"cell_type":"markdown","source":"**a.  Change to rule 9 (Scrimmage Kick)  section 1:**\n\n\n** At most two players from both kicking and receiving team can be lined up outside of yard number, one for each side of the field**\n"},{"metadata":{"_uuid":"418983eb79b88bb2ab9c91d3a54e8ecfe528dfee"},"cell_type":"markdown","source":"Before talking about the rule change let's discuss about punt coverage in football. In NFL, there is a regulation for defesive formation:\n\nNFL rule 9-1-2:\n\nDuring a kick from scrimmage, only the end men (eligible receivers) on the line of scrimmage at the time of the snap, or an eligible receiver who is aligned or in motion behind the line \nand is more than one yard outside the end man, are permitted to advance more than one yard beyond the line before the ball is kicked.\n\nSince only elgible receiver can cover the punt before the kick, NFL teams cannot ultilize a \"shield punt formation\" and therefore most punt in the the league end up like:\n\n![](https://mgoblog.com/sites/mgoblog.com/files/Oldpunt.jpg)\n\n\nwhere two wide receiver at the end act as gunner to cover the punt, and the rest of the team to protect the punt kick.\n\nFor the receiving team, there are three types of formation, depends on number of player cover against opponent's gunner: \n\nSingle coverage\n\n![](https://imgur.com/7xMiR2j.jpg)\n\nDouble coverage\n\n![](https://imgur.com/dKGrWie.jpg)\n\nHybrid coverage\n\n![](https://imgur.com/2LQiOXe.jpg)\n\n\nLet's check the effect of coverage on concussion chance:\n"},{"metadata":{"trusted":true,"_uuid":"eee01224d69d50c6cc7dc99172255dccef1e909c"},"cell_type":"code","source":"single_coverage = all_punt_data[(all_punt_data['VR'] == 1) & (all_punt_data['VL'] == 1) ]\n\ndouble_coverage = all_punt_data[(all_punt_data['VR'] == 0) & (all_punt_data['VL'] == 0) ]\n\nhybrid_coverage = all_punt_data[(all_punt_data['VR'] == 0) ^ (all_punt_data['VL'] == 0) ]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"aff4ae7139ccebd2e52968c1abf80fc9b3aea006","scrolled":true},"cell_type":"code","source":"print(\"Number of single coverage punt: %d\" % len(single_coverage))\nprint(\"Concussions from single coverage punt: %d\\n\" % single_coverage.Primary_Impact_Type.notna().sum())\nprint(\"Number of hybrid coverage punt: %d\" % len(hybrid_coverage))\nprint(\"Concussions from hybrid coverage punt: %d\\n\" % hybrid_coverage.Primary_Impact_Type.notna().sum())\nprint(\"Number of double coverage punt: %d\" % len(double_coverage))\nprint(\"Concussions from double coverage punt: %d\" % double_coverage.Primary_Impact_Type.notna().sum())","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a82c25784f1511c44e38e87a4d155750887cf52c"},"cell_type":"markdown","source":"But bear in mind that coaches tends to deploy different coverage depends on punting line of scrimmage"},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"d02f0cb9274aa97dda0d05fcbe7a47d470c68b87"},"cell_type":"code","source":"print(\"single coverage average starting yardline = %1.1f\" % np.nanmean(np.array(single_coverage.adjust_yardline).astype(float)))\nprint(\"hybrid coverage average starting yardline = %1.1f\" % np.nanmean(np.array(hybrid_coverage.adjust_yardline).astype(float)))\nprint(\"double coverage average starting yardline = %1.1f\" % np.nanmean(np.array(double_coverage.adjust_yardline).astype(float)))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"08ba64d3a582004c8cbdba2c3c55d88f2270b6b4"},"cell_type":"markdown","source":"So we would like to find the effect of coverage after control for yardline using Statsmodels package"},{"metadata":{"_kg_hide-output":true,"trusted":true,"_uuid":"0379637fed4b1988daa417638d2de41a9bf56a72","scrolled":false,"_kg_hide-input":true},"cell_type":"code","source":"hybrid_coverage['coverage_type'] = 0\nsingle_coverage['coverage_type'] = 1\ndouble_coverage['coverage_type'] = 2\n\nregression_df = pd.concat([single_coverage,double_coverage,hybrid_coverage])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"79d8ad44a987ccd830abca522264090845e8e217"},"cell_type":"code","source":"import statsmodels\nimport statsmodels.api as sm\n\nimport statsmodels.formula.api as smf\n\n\nresults = smf.logit(formula='returned ~ C(coverage_type) + adjust_yardline', data=regression_df).fit()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"28323677fbfafbd78c3f33f11d93b739c2c9a455","scrolled":false},"cell_type":"code","source":"results.summary()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d70ef380bed26bfe3796724521f0aa3b2a9f2287"},"cell_type":"code","source":"print(\"Odd ratio of return for single coverage compare to hybrid coverage = %f\" % np.exp(results.params)[1])\nprint(\"Odd ratio of return for single coverage compare to double coverage = %f\" % (np.exp(results.params)[1] * np.exp(results.params)[2]))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"faf640e8b4502ac23a38393c0bb5d7b9ef4eeb2d"},"cell_type":"markdown","source":"It demostartes that single coverage formation can significatly decrease the chance of returning a punt even after adjusted for starting yardline. \n\nWe would also like to find the effect of coverage on average yards per punt."},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"afc1e04dacb65924b03ae500da55748097e5cd08"},"cell_type":"code","source":"regression_df_punt = regression_df.dropna(subset=['punt_yards'])\nregression_df_return = regression_df.dropna(subset=['return_yards'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9712c5bcc4727b2864c894f9608b4343a02e76fa"},"cell_type":"code","source":"results = smf.ols(formula='punt_yards ~ adjust_yardline +  C(coverage_type)', data=regression_df_punt).fit()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e9e03cee97f5c797e6b865bcfc08b232c5b72157","scrolled":false},"cell_type":"code","source":"results.summary()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"41dec31a4fdfdd9740c2b17cc316ecc91367ba02"},"cell_type":"markdown","source":"Here it shows that a hybrid coverage would increase average yards per punt, but no significant relation found on the difference between single and double coverage. Which means that the rule change fits our goal: limit the number of returns, but receiving team can still try to advance the ball as before."},{"metadata":{"trusted":true,"_uuid":"19ed5ac31dc6f8cf6c1e34a1a62caa9c893bc716","scrolled":true},"cell_type":"markdown","source":"**b.  Change to rule 10 (Opportunity to catch a kick, fair catch)  section 2 article 4:**\n\n\n** After a fair catch is made, the receiving team can put the ball in play by a snap from 5 yards in front of spot of the catch if the catch is off a punt kick**\n\nSimply speaking, it's to award the receiving team for 5 yards after they have a fair catch off a punt. \n"},{"metadata":{"_uuid":"05af6b36147b8a7c8cd54de49e3a81ee3a5209cb"},"cell_type":"markdown","source":"From the first rule change, we can tell how much less likely for receive team after banning double coverage formation. We shall use punt from own 34 as example at it close to average punt line of scrimmage."},{"metadata":{"trusted":true,"_uuid":"ac2db61c425293f934145a3233d937d5f7ba190f"},"cell_type":"code","source":"print(\"Average punting line of scrimmage = %1.3f\\n\" % np.mean(all_punt_data['adjust_yardline']))\n\nprint(\"Probability of return a punt from 34 yardlime for single coverage: %f\" % (math.exp(-0.679+2.133-0.0623*34) / (1+math.exp(-0.679+2.133-0.0623*34))))\nprint(\"Probability of return a punt from 34 yardlime for hybrid coverage: %f\" % (math.exp(0+2.133-0.0623*34) / (1+math.exp(0+2.133-0.0623*34))))\nprint(\"Probability of return a punt from 34 yardlime for double coverage: %f\" % (math.exp(0.208+2.133-0.0623*34) / (1+math.exp(0.208+2.133-0.0623*34))))\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"00e0d6faae83490c732af87ec74475b83d62a936"},"cell_type":"markdown","source":"Also we can output  punt return data for different coverage."},{"metadata":{"trusted":true,"_uuid":"8b048ca5a31cf36f0129d69b961e6ce1f101c8f3","scrolled":false},"cell_type":"code","source":"print(\"Number of return of all punt = %d\\n\"% np.nansum(np.array(all_punt_data.returned).astype(float)) )\n\nprint(\"Single coverage number of return = %d\" % np.nansum(np.array(single_coverage.returned).astype(float)))\nprint(\"Hybrid coverage number of return = %d\" % np.nansum(np.array(hybrid_coverage.returned).astype(float)))\nprint(\"Double coverage number of return = %d\\n\" % np.nansum(np.array(double_coverage.returned).astype(float)))\n\n\n\nprint(\"Average yards per return of all punt = %1.2f\\n\"% np.nanmean(np.array(all_punt_data.return_yards).astype(float)) )\n\nprint(\"Single coverage average yards per return = %1.2f\" % np.nanmean(np.array(single_coverage.return_yards).astype(float)))\nprint(\"Hybrid coverage average yards per return = %1.2f\" % np.nanmean(np.array(hybrid_coverage.return_yards).astype(float)))\nprint(\"Double coverage average yards per return = %1.2f\" % np.nanmean(np.array(double_coverage.return_yards).astype(float)))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"f2a86b249f61a404b6a846999f4bd2c779105dd7"},"cell_type":"markdown","source":"Using linear regression to see the decrease of return yards for single coverage:"},{"metadata":{"trusted":true,"_uuid":"cc8d6ad78fa70474a0709cbb203d374fe64ec725"},"cell_type":"code","source":"results = smf.ols(formula='return_yards ~ adjust_yardline +  C(coverage_type)', data=regression_df_return).fit()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":false,"_uuid":"3efaa8aa84ae4917a3fade65e40cd3d36aca3a85"},"cell_type":"code","source":"results.summary()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"4766a8fc05cafe7c4e4418a591f21145bac73c72"},"cell_type":"markdown","source":"After considering direct decrease in punt yards and decrease in punt return chance, we can calculate how effective punt yards change\n\nFormula: $\\%{  }of{ }play \\times ( {decrease\\text{  }in\\text { }return\\text{ }yards} + {decrease\\text{  }in\\text { }return\\text{ }chance} \\times {average\\text{  }return\\text { }yards} )$\n\n"},{"metadata":{"trusted":true,"_uuid":"5779b8f13a7e746b08a32045e859c50913c094e6"},"cell_type":"code","source":"print(\"Decrease in effective punt yards at own 34 = %1.2f\" % ((1865/(1865+1423+3379))*(1.03+(0.503-0.34)*(11-0.0695*34-1.03))+(1423/(1865+1423+3379))*((1.03-0.12)+(0.55-0.34)*(11-0.0695*34-1.03+0.12))))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b6677932472711d65e57ee18eea72482b728cbe1"},"cell_type":"markdown","source":"After calculation, we find that on average receiving team lose about 1.2 yards due to rule change. As to compensate the effect, it is suggested that 5 yards is awarded to receiving team for each fair catch. Similar to kickoff rule changes happens a 2016 which change touchback line to 25 yard, the change may let receiving team to go for fair catch more and hence decrease the number of concussion."},{"metadata":{"trusted":true,"_uuid":"2e54910eb2981438acf34bb23871f2bb93598986"},"cell_type":"markdown","source":"\n**c. Point of Emphasis: Protection of kick returner**\n\n**Special teamer cannot lower their head to tackle kick returner**\n\nPoint of emphasis is not really a rule change, but a guideline to referees for better gaming integrity in the comming season. \n\n\nIn 2016-17, half of the concussions in punt plays are due to tackling, and punt returner has the highest risk of concussion in all positions. After reviewing the video, quite a number of them are due to head first tackle by kicking team. The tackling technique put both the tackler and returner at a higher risk to sustain injuries. Here are video examples how head-first tackle increase concussion risk\n"},{"metadata":{"_uuid":"d376e5a07098ff145463db3594cbae2ba9c63e3d"},"cell_type":"markdown","source":"Tackler injury"},{"metadata":{"_kg_hide-input":false,"_uuid":"d6039492d9ef4a1ff26344e518fc000db27998a3","trusted":true},"cell_type":"code","source":"HTML('<video width=\"800\" height=\"600\" controls> <source src=\"http://a.video.nfl.com//films/vodzilla/153233/Kadeem_Carey_punt_return-Vwgfn5k9-20181119_152809972_5000k.mp4\" type=\"video/mp4\"></video>')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d198ef1b0df880b997d2809f78941b85ebfd0149"},"cell_type":"markdown","source":"Returner injury"},{"metadata":{"trusted":true,"_uuid":"b6235b1631c126f529e722f23c7e13dac62a6318"},"cell_type":"code","source":"HTML('<video width=\"800\" height=\"600\" controls> <source src=\"http://a.video.nfl.com//films/vodzilla/153274/Haack_punts_41_yards-SRJMeOc3-20181119_165546590_5000k.mp4\" type=\"video/mp4\"></video>')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"1e606ced631cc3cabd3d06aee680e9f81da89927"},"cell_type":"markdown","source":"In 2018 season, NFL has implement on rule change that it is a foul if a player lowers his head to initiate and make contact with his helmet against an opponent. Contact does not have to be to an opponent’s head or neck area. From [nflpenalties.com](http://www.nflpenalties.com/penalty/lowering-the-head-to-initiate-contact?year=2018&view=log) we can see the statistic of targeting penalty\n\n![](https://imgur.com/7XYCMQf.png)\n\nWe can see out of 16 penalties called in till the end of 2018 regular season, 15 of them are called on defense and the remaining one is on offense, which means none of them is called during special team play. \nTherefore, referee can pay attention on players' tackling technique during punt return and penalize those who use head-first tackle. Here are some examples of safe \"wrap up\"technique from control group video footage:\n\n"},{"metadata":{"trusted":true,"_uuid":"b3116dab0c98e422a49f751a83e6420c21612159"},"cell_type":"code","source":"HTML('<video width=\"800\" height=\"600\" controls> <source src=\"http://a.video.nfl.com//films/vodzilla/153511/Lechler_58_yard_punt-8LArhoQg-20181121_123420599_5000k.mp4\" type=\"video/mp4\"></video>')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"dc370895f4453db68294c7ee23a55dae8c95532c"},"cell_type":"code","source":"HTML('<video width=\"800\" height=\"600\" controls> <source src=\"http://a.video.nfl.com//films/vodzilla/153517/Schmidt_57_yard_punt-EMXj28Mw-20181121_124742503_5000k.mp4\" type=\"video/mp4\"></video>')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"f7f54de8e5cdd0f4221e1e9b174fb6a078414d73"},"cell_type":"markdown","source":"**4. Discussion of other possible rule changes**\n\nHere I would discuss other possible rule changes as well as their pro and cons. They are not included in the main sessions above due to possible difficulties for implementation.\n\n**a.  Limit number of players of receiving team to block the punt**\n\nThe rule can be implemented by limit number of players crossing line of scrimmage when opponent present a punt formation\n\nWe may look at how many players attmept to block punt in each players, where I define as number of players with 10 yards of punter at the time of the punt"},{"metadata":{"trusted":true,"_uuid":"92e9608bc9dc27494a46886b8cddd77da104b97e"},"cell_type":"code","source":"file_location = ['NGS-2016-pre.csv', 'NGS-2016-reg-wk1-6.csv', 'NGS-2016-reg-wk7-12.csv', 'NGS-2016-reg-wk13-17.csv','NGS-2016-post.csv',\n                 'NGS-2017-pre.csv', 'NGS-2017-reg-wk1-6.csv', 'NGS-2017-reg-wk7-12.csv', 'NGS-2017-reg-wk13-17.csv','NGS-2017-post.csv']\n\ntracking_df = pd.DataFrame()\n\nfor i in range(10):\n    data = pd.read_csv('../input/' + file_location[i])\n    data = pd.merge(data,play_information_data,how='outer')\n    data = pd.merge(data,player_role_data,how='outer')\n    punter_data = data[(data.Event=='punt') & (data.Role == 'P')][['x','y','Season_Year' ,'GameKey','PlayID','Time']]\n    punter_data.columns = ['punter_x', 'punter_y','Season_Year','GameKey','PlayID','Time']\n    receiving_position = ['PDL1', 'PDL2','PDL3', 'PDL4', 'PDL5', 'PDL6', 'PDM', 'PDR1', 'PDR2', 'PDR3','PDR4', 'PDR5', 'PDR6', 'PFB','PLL', 'PLL1', 'PLL2',\n       'PLL3', 'PLM', 'PLM1', 'PLR', 'PLR1', 'PLR2', 'PLR3','VL', 'VLi', 'VLo', 'VR', 'VRi', 'VRo', 'PR']\n\n    punt_time = np.array(punter_data.Time)\n    playid = np.array(punter_data.PlayID)\n    gamekey = np.array(punter_data.GameKey)\n\n    receiving_team_data = data[(data.Event=='punt') & (data.Role.isin(receiving_position))] #All member of receiving team at time of punt\n    \n    merged_data = pd.merge(receiving_team_data,punter_data,how='left').dropna()\n    merged_data['distance_to_P'] = ((merged_data['x'] - merged_data['punter_x'])**2-(merged_data['y'] - merged_data['punter_y']))**0.5\n    output_df = merged_data[merged_data['distance_to_P'] < 10].groupby(['Season_Year','GameKey','PlayID'])['Role'].count().reset_index() #group all receiving team player around 10 yards of punter\n    output_df.columns = ['Season_Year', 'GameKey', 'PlayID', 'no_blocker']\n\n    \n    tracking_df = tracking_df.append(output_df)      ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"686d1e04df3ffc220a58a842e3875185eb97a901"},"cell_type":"code","source":"all_punt_data = pd.merge(all_punt_data,tracking_df)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b3e171e9f8fd36648b27cd25956b0230d80e24ac"},"cell_type":"code","source":"pd.value_counts(all_punt_data['no_blocker']).plot.bar()\nplt.title('Number of blockers in punt')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"4941f840529f1645936047fd1b9ce0a7a603a18a"},"cell_type":"markdown","source":"We can also check how number of blockers affect chance of concussion"},{"metadata":{"trusted":true,"_uuid":"190a068039d1112a6ebdb16713c7feafe77ba200"},"cell_type":"code","source":"results = smf.logit(formula='concussed ~ adjust_yardline  + no_blocker', data=all_punt_data).fit()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9ea77729bff16e0c9fdd16039783f9d0b419c30f"},"cell_type":"code","source":"results.summary()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0c2d46f42ad57932bd7c150c0c3dab367369e4f4"},"cell_type":"markdown","source":"Turn out that it's possible to number of blockers has an impact on number of concussion\n\n**Problem:**\n\n**1. Possible abusement in field goal**\n\nIn NFL there is no restriction when and where to present a punt formation. Therefore, if number of blockers for defense is limited, a team which attempt a field goal can present a punt formation to aviod getting blocked or draw penalty by faking field goal and punt instead.\n\n**2. Increase in number of returns and lead to more concussions:**\n\nDecrease of number of blockers will lead to increase in punt return, presumably would increase the risk of concussion"},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"d460984cc1f6b0c4d315760ce71c3993b99c969a"},"cell_type":"code","source":"results = smf.logit(formula='returned ~ adjust_yardline  + no_blocker', data=all_punt_data).fit()\nresults.summary()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"071d01cf6baef921a30067ba267a71fecb5bfdac"},"cell_type":"markdown","source":"**b. Limit the number of overload defender**\n\nIn current NFL rule, when opponent present a field goal or try kick (extra point) formation, defense cannot punt more than six players on each side of the snapper (NFL rulebook 9-3-2(2)). We would see the effect of number of overload defender (i.e. unbalanced number of player on each side of the field) for punt play.\n"},{"metadata":{"trusted":true,"_uuid":"e6eddb1321abe6cc613638bf6074c35596456899"},"cell_type":"code","source":"all_punt_data['overload'] =  ((all_punt_data['PDL1'] + all_punt_data['PDL2'] + all_punt_data['PDL3'] + all_punt_data['PDL4'] + all_punt_data['PDL5'] + all_punt_data['PDL6']) - \\\n(all_punt_data['PDR1'] + all_punt_data['PDR2'] + all_punt_data['PDR3'] + all_punt_data['PDR4'] + all_punt_data['PDR5'] + all_punt_data['PDR6']) + \\\n(all_punt_data['PLL1'] + all_punt_data['PLL2'] + all_punt_data['PLL3']) - \\\n(all_punt_data['PLR1'] + all_punt_data['PLR2'] + all_punt_data['PLR3'])).abs()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"4f6d5b4c8f43b04ebc2775c74854dedd731baffc"},"cell_type":"code","source":"results = smf.logit(formula='concussed ~ adjust_yardline  + overload', data=all_punt_data).fit()\nresults.summary()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6835a3b7143573a5f7251763fdd6593e7ca96fd2"},"cell_type":"code","source":"results = smf.logit(formula='returned ~ adjust_yardline  + overload', data=all_punt_data).fit()\nresults.summary()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8a4a4bcec2d5b9bbf45a8c16c43c918478a5d221"},"cell_type":"markdown","source":"**Problem: **\n\nWe can see number of overload defender neither affect the concussion chance nor rate of returning the punt. The rule change is easily implemented, but probably cannot meanfully decrease number of concussions"},{"metadata":{"_uuid":"fc4b6c953b416a09b9c487530e109629407d6965"},"cell_type":"markdown","source":"**c. players from kicking team need to have at least 5 yards from punt returner**\n\nIn Canadian football, there is no fair catches. Instead, kicking team player need to be at least 5 yards from the returner. Teams who violate will be given a \"no yards\" penalty. Let's check the data of gunner within 5 yards."},{"metadata":{"trusted":true,"_uuid":"c3b869ff29020e66485091e94f89b839574a77f7"},"cell_type":"code","source":"file_location = ['NGS-2016-pre.csv', 'NGS-2016-reg-wk1-6.csv', 'NGS-2016-reg-wk7-12.csv', 'NGS-2016-reg-wk13-17.csv','NGS-2016-post.csv',\n                 'NGS-2017-pre.csv', 'NGS-2017-reg-wk1-6.csv', 'NGS-2017-reg-wk7-12.csv', 'NGS-2017-reg-wk13-17.csv','NGS-2017-post.csv']\n\ntracking_df = pd.DataFrame()\n\nfor i in range(10):\n    data = pd.read_csv('../input/' + file_location[i])\n    data = pd.merge(data,play_information_data,how='outer')\n    data = pd.merge(data,player_role_data,how='outer')\n    returner_data = data[((data.Event=='fair_catch') | (data.Event=='punt_received')) & (data.Role == 'PR')][['x','y','Season_Year' ,'GameKey','PlayID','Time']]\n    returner_data.columns = ['punter_x', 'punter_y','Season_Year','GameKey','PlayID','Time']\n    receiving_position = ['PDL1', 'PDL2','PDL3', 'PDL4', 'PDL5', 'PDL6', 'PDM', 'PDR1', 'PDR2', 'PDR3','PDR4', 'PDR5', 'PDR6', 'PFB','PLL', 'PLL1', 'PLL2',\n       'PLL3', 'PLM', 'PLM1', 'PLR', 'PLR1', 'PLR2', 'PLR3','VL', 'VLi', 'VLo', 'VR', 'VRi', 'VRo', 'PR']\n\n    return_time = np.array(returner_data.Time)\n    playid = np.array(returner_data.PlayID)\n    gamekey = np.array(returner_data.GameKey)\n\n    kicking_team_data = data[((data.Event=='fair_catch') | (data.Event=='punt_received')) & ~(data.Role.isin(receiving_position))] #All member of receiving team at time of punt\n    \n    merged_data = pd.merge(kicking_team_data,returner_data,how='left').dropna()\n    merged_data['distance_to_PR'] = ((merged_data['x'] - merged_data['punter_x'])**2-(merged_data['y'] - merged_data['punter_y']))**0.5\n    output_df = merged_data[merged_data['distance_to_PR'] < 5].groupby(['Season_Year','GameKey','PlayID'])['Role'].count().reset_index() #group all receiving team player around 10 yards of punter\n    output_df.columns = ['Season_Year', 'GameKey', 'PlayID', 'close_defender']\n\n    \n    tracking_df = tracking_df.append(output_df)      ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"80591a22930fc7058ef1561e38e6d941f012b71f"},"cell_type":"code","source":"close_defender_data = pd.merge(all_punt_data,tracking_df)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":false,"_uuid":"4d946b59f921a1dd8a89136896a33cee91e41ccc"},"cell_type":"code","source":"pd.value_counts(close_defender_data['close_defender']).plot.bar()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"19c141f16722a686b34d13bd8c1f355509a1dd07"},"cell_type":"code","source":"results = smf.logit(formula='returned ~ close_defender + adjust_yardline', data=close_defender_data).fit()\nresults.summary()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":false,"_uuid":"08772b8edced3c49bbfa0f66ca9e8f9588affb4e"},"cell_type":"code","source":"results = smf.logit(formula='concussed ~ close_defender + adjust_yardline', data=close_defender_data).fit()\nresults.summary()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"122df7eba4c4b7215f9af2842482a4e3af326583"},"cell_type":"markdown","source":"Also for fair catches in punt in NFL:"},{"metadata":{"trusted":true,"_uuid":"6fe2e049f76ae51d65fc37d38e984a117511871f"},"cell_type":"code","source":"results = smf.logit(formula='concussed ~ fair_catch + adjust_yardline', data=all_punt_data).fit()\nresults.summary()","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-output":false,"_uuid":"700483e1d1dccbfbefae63aa6609248b44634598"},"cell_type":"markdown","source":"We can see number of close defender significantly decrease the number of return, but it's doesn't really mean much since returner will more likely to have more fair catch. It doesn't affect concussion chance significantly either.\n\n**Problem: **\n\nNumber of defender within returner's proximityis more of a symptom than an actual meaningful attribute, and it has no edvidence to shows it helps since from above discussion we know that returning punt is highly assiosiate with concussion.  The reason of CFL has the penalties is that it has no fair catch, and  it is shown that fair catches has significantly decrease number of concussion."},{"metadata":{"_uuid":"1d14f2c6fb6c2537db0aab4507f6e39539276046"},"cell_type":"markdown","source":"**f. Abolish punt return**\n\nAnother way to abolish punt return and put the ball at the spot where the punt land.\n\n**Problem:**\n\n**1. Affect ability to score in late game**\n\nIt will decrease the ability for  team to make a comeback or take the lead in late game. For example at 2010 week 15 Eagles vs Giant (dubbed \"[Miracle at the New Meadowlands](https://www.youtube.com/watch?v=2PufejLOdzs)\"), Eagles overcome a 21 points deficit with 8 minutes remaining and score a game-winning touchdown when clock expire. Without punt return, it would be harder for trailing team to comeback.\n\n**2. Eliminate punter in NFL**\n\nOne of the reason why NFL team have one punter and one placekicker is that they provide different skill set: kicker has to have good accuracy to make field goal, while punter need good control of the ball so as to limit return and let opponent start at a disadvantage position. If punt return is abolish it probably take less skill to become a punter, and thus pushing them out of the league."},{"metadata":{"_uuid":"a38b79d676006eba1b976738f16674b90e816da7"},"cell_type":"markdown","source":"**e. Abolish punting**\n\nIt may not fit the theme of the competition, but there are discussions that if rule changes does not limit the number of concussions in kickoff, NFL may consider to ban kickoff and put the ball on a fixed line after scoring.\n\n**Problem:**\n\n**1. Concussion risk **\n\nFrom above data, punt contribute for 8.3% of concussion but it's over [18% for kickoff](https://www.washingtonpost.com/news/early-lead/wp/2018/03/28/could-the-nfl-ban-kickoffs-concussion-concerns-have-idea-moving-closer-to-reality/?utm_term=.06ed4fce4b4f). The inherit risk of getting concussed in a punt play is much lower than kickoff. If NFL hasn't get rid of kickoff, punting probably won't disappear anyway.\n\n**2. Implementaion problem**\n\nFor kickoff the league can choose an arbitary yardline to put the ball on, but for punt there isn't one, especially punt yards is highly dependent of line of scrimmage of punting team.\n\n**3. Affect ability to score in late game**\n\n**4. Eliminate punter in NFL**\n\nSee section (d) above"},{"metadata":{"trusted":true,"scrolled":false,"_uuid":"71fc133ecc5591c5a6809f51c38fe02df0b3d2b5"},"cell_type":"code","source":"all_punt_data[['punt_yards','adjust_yardline']].groupby('adjust_yardline').mean().plot(kind='bar')\nplt.xticks([])\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8f2bf5e8411219be4c071d9662064cfcab87a075"},"cell_type":"markdown","source":"So here is the end of the kernel and thanks for reading. Feel free to point out any mistakes I made or other suggestions!"}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}