{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"\nimport numpy as np \nimport pandas as pd \n\n\nimport os\nprint(os.listdir(\"../input\"))\n","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e0461d823cf5640c884d3e2735f0636688bbf8e8"},"cell_type":"code","source":"#Combining a few tables to get a clean look at the details of plays that resulted in concussions\n\nvideo_review = pd.read_csv('../input/NFL-Punt-Analytics-Competition/video_review.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"37d526ac03b2225daea45a720f8161e0fc704e28"},"cell_type":"code","source":"video_review.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3d8af5831909579b6dc7f407f1b389f6b96af8fd"},"cell_type":"code","source":"position = pd.read_csv('../input/NFL-Punt-Analytics-Competition/play_player_role_data.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d1c2586940feb208ba03cbf9d012374562c90079"},"cell_type":"code","source":"position.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1a8e6f253783715aefe7f690dadde4aa33d3e224"},"cell_type":"code","source":"concussion_play_data = pd.merge(video_review,position)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"52e2230513baaa70c51493c866467e48f0c57605"},"cell_type":"code","source":"concussion_play_data.head()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"9ce192219b2a024952b5df1454b5c81dd96fd175"},"cell_type":"markdown","source":"Let's start to explore. Are there activities or positions that are more likely to sustain concussions?"},{"metadata":{"trusted":true,"_uuid":"0c7fa8bb2f1c23e94262075d88b52b1e10b6c82e"},"cell_type":"code","source":"concussion_play_data.Role.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"311643ea63bf17a184e021b94bf19d89d6509df2"},"cell_type":"code","source":"concussion_play_data.groupby('Player_Activity_Derived').Role.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"6d931f1a538289bd63fc7f67c642f3bb9a70630d"},"cell_type":"markdown","source":"It seems like there might be something here, but we don't have a clear view of which team is more impacted. Let's map the positions to the punting or receiving team based on the position charts provided in the dataset."},{"metadata":{"trusted":true,"_uuid":"63c66447f14a8fd3b6103ef0a27bdec8944e695b"},"cell_type":"code","source":"team = {'GL':'Punting','PLT':'Punting','PLG':'Punting','PLS':'Punting','PRG':'Punting','PRT':'Punting','GR':'Punting','PLW':'Punting','PRW':'Punting','PC':'Punting','PPR':'Punting','P':'Punting','VRo':\"Receiving\",'VRi':\"Receiving\",'PDR1':\"Receiving\",'PDR2':\"Receiving\",'PDR3':\"Receiving\",'PDL3':\"Receiving\",'PDL2':\"Receiving\",'PDL1':\"Receiving\",'PLR':\"Receiving\",'PLM':\"Receiving\",'PLL':\"Receiving\",'PFB':\"Receiving\",'PR':\"Receiving\",'PDL4':\"Receiving\",'VLo':\"Receiving\",'VR':'Receiving'}\n\nconcussion_play_data['Team']=concussion_play_data.Role.replace(team)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ec77987714a3287f64f19d09c3262034fd5d9213"},"cell_type":"code","source":"concussion_play_data.Team.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"3d38dd3efb8a1b827c7fd3bdce8bff0cd587d3e0"},"cell_type":"markdown","source":"Very interesting! Players from the punting team sustained concussions at a rate of nearly 3:1 over the receiving team!"},{"metadata":{"trusted":true,"_uuid":"270626ced913af6eb7c2b28e4b2bd592cacecbc5"},"cell_type":"code","source":"concussion_play_data.groupby('Team')['Player_Activity_Derived'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5b4b3ef501aba468c00c05c140a219f8fb018645"},"cell_type":"code","source":"sns.countplot(x='Player_Activity_Derived', data=concussion_play_data, hue='Team')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"7cbbac12f3e3b46169382caa024f969a1e571824"},"cell_type":"markdown","source":"Tackles are dangerous! \n\nClearly, a good outcome of the proposed rule changes will be reducing the number of collisions on punt plays.\n\nAre there any additional areas that we can focus on? The chaos from a turnover? Gunners launching themselves on a tackle?"},{"metadata":{"trusted":true,"_uuid":"e62ac66d754b60560819b903fa9f6646efb6e77b"},"cell_type":"code","source":"concussion_play_data['Turnover_Related'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"e2c63c348744e49e62019362f467b1110a175f48"},"cell_type":"markdown","source":"No concussions were the result of a turnover"},{"metadata":{"trusted":true,"_uuid":"c07d90491529c7e9c891ee5f029f6d47b3b5f2e1"},"cell_type":"code","source":"concussion_play_data.groupby('Team').Role.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a018a2c33b295c346748adcb77f1875a708eed43"},"cell_type":"code","source":"sns.countplot(x='Role', hue='Team', data = concussion_play_data)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"257575b6b4266279417450d529934c9b19a78249"},"cell_type":"markdown","source":"We would fully expect that Punt Returners (PR) would be at risk of concussion. It also stands to reason that players on the outside of the punting formation would be at risk as they are most often involved in tackling.\n\nAre there types of impacts that are riskier?"},{"metadata":{"trusted":true,"_uuid":"27a5f011b9b4db27b50bd26b28a13a92c488b5de"},"cell_type":"code","source":"concussion_play_data['Primary_Impact_Type'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c3def386437ec310a7b7cf2f83fc871a59ab7356"},"cell_type":"code","source":"sns.countplot(x='Primary_Impact_Type', data=concussion_play_data)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"58d9c0d876c9ae59d6e3797571d2663b764c8896"},"cell_type":"markdown","source":"Not really. Helmet-to-helmet hits have been a focus of the league and will continue to be so, but occurred at the same rate as helmet-to-body contact, which would be nearly impossible to prohibit.\n\nHow do these plays compare to the remaining punt plays that did not result in a concussion?"},{"metadata":{"trusted":true,"_uuid":"513362ac59f87c128a6cfd9a1843ff6af6c3a736"},"cell_type":"code","source":"#Create a unique identifier for each game by combining GameKey and PlayID\n\nconcussion_play_data['GameKey_PlayID'] = concussion_play_data['GameKey'].map(str) + concussion_play_data['PlayID'].map(str)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a901985e4114c66950de7ea88e2b42d825f23cfa"},"cell_type":"code","source":"concussion_play_data.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7fce2c7a5552976947588274b391a02c1b22be01"},"cell_type":"code","source":"#Assign True value for all concussions in this data set\nconcussion_play_data['Concussion'] = 'True'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5378da15a217b34dafd9212501cb890d7d328af1"},"cell_type":"code","source":"#Read in remaining play data (including concussion punts)\n\nall_plays = pd.read_csv('../input/play-informationcsv/play_information.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6edcbdfa9be75b46a8b147e18135cdf6fb29d9d2"},"cell_type":"code","source":"all_plays.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"acf8c66e00c6ba93def4e21dde9cb6a756cfb01e"},"cell_type":"code","source":"#A little offline manipulation for time's sake. \n#Here Territory = 0 for a punt from the punting team's side of the field; Territory = 1 for a punt from the receiving team's side of the field\n\nall_plays.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"19ae0c1c1dbf9eba6a1aaeb4de9cdad550f76e59"},"cell_type":"code","source":"#To merge tables, check that PlayID is unique\n\nall_plays.PlayID.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a1d1b423ef596f6216fa5e39153d6720cf1e0235"},"cell_type":"code","source":"# PlayID is not unique! So we create a unique identifier to merge the tables by combining GameKey and PlayID and removing the lone duplicate\nall_plays['GameKey_PlayID'] = all_plays['GameKey'].map(str) + all_plays['PlayID'].map(str)\nall_plays['GameKey_PlayID'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bd8177f11c12aa6281ba9c673a1926866153cb10"},"cell_type":"code","source":"#Visualize the only duplicate from our unique identifier\n\nall_plays[all_plays['GameKey_PlayID']=='613849']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"dde60fd48b16dda6e154ff838fdce7ad5eff9132"},"cell_type":"code","source":"#Remove duplicate by adding a and b\n\nall_plays.iloc[697, all_plays.columns.get_loc('GameKey_PlayID')] = '613849a'\nall_plays.iloc[6124, all_plays.columns.get_loc('GameKey_PlayID')] = '613849b'","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"6e928cbef569ad65626e6f8b81222217171ce7d6"},"cell_type":"markdown","source":"Much of the interesting details about the plays are contained in the long string called 'PlayDescription', so let's play with that and encode some more variables before merging tables"},{"metadata":{"trusted":true,"_uuid":"a4ce3eba440b0b2471d616ecb4696fb0fe1cacd1"},"cell_type":"code","source":"#Assigns True to 'fair_catch' if the 'PlayDescription' contains the phrase 'fair catch'\n\nall_plays['fair_catch'] = all_plays['PlayDescription'].str.contains('fair catch')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c29db6b786b07a0826613c84d5f51605a85fdf86"},"cell_type":"code","source":"#Assigns True to 'Touchback' if the 'PlayDescription' contains the phrase 'Touchback'\n\nall_plays['Touchback'] = all_plays['PlayDescription'].str.contains('Touchback')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0de2fd7577d79c1a64b936cb036cc29cb45ebb5b"},"cell_type":"code","source":"#Assigns True to 'out_of_bounds' if the 'PlayDescription' contains the phrase 'out_of_bounds'\n\nall_plays['out_of_bounds'] = all_plays['PlayDescription'].str.contains('out of bounds')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"aeeb6d36bcbc5866ee2db12a9f761ebdeac71155"},"cell_type":"code","source":"#Assigns True to 'out_of_bounds' if the 'PlayDescription' contains the phrase 'out_of_bounds'\n\nall_plays['downed'] = all_plays['PlayDescription'].str.contains('downed')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"de4343037be43742cc570442ac710bb18120159d"},"cell_type":"code","source":"#Manipulate the string for 'PlayDescription' to capture the distance of the punt\n\nnew = all_plays['PlayDescription'].str.split(pat='punts',n=1, expand=True)\nall_plays['split1'] = new[0]\nall_plays['split2'] = new[1]\nall_plays['distance'] = all_plays['split2'].str.extract('(\\d+)')\nall_plays.drop(columns=[\"split1\",\"split2\"], inplace=True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cbf083c7ceb58770edd3fd4bff7e91ff894be574"},"cell_type":"code","source":"all_plays['distance']=all_plays['distance'].fillna(0)\nall_plays['distance'] = all_plays['distance'].map(int)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e6cee9c5601504b8bd8e8fbf0d57e2f39c3f20df"},"cell_type":"code","source":"#Great, let's merge tables to get the full universe of all punt plays from the 16-17 seasons with our new variables\nfull_data = pd.merge(all_plays, concussion_play_data, on='GameKey_PlayID', how='left')\nfull_data.info()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"832d64c24dee0e6292d0e22ea192d8e47b17be82"},"cell_type":"markdown","source":"We now have a universe of **6,681 punt plays** from the 16-17 seasons that resulted in **37 concussions**.\n\nLet's visualize once again the 37 plays that resulted in a concussion."},{"metadata":{"trusted":true,"_uuid":"f5429ce4469b650831b0db417afde0ed38a3402f"},"cell_type":"code","source":"full_data[full_data['Concussion'] == \"True\"]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"25ba50dc0f413e189b1c3f54e9fe5d2ddaf34b3b"},"cell_type":"code","source":"# 'Concussion' will be our target, so we fill the concussion column with False for NA\n\nfull_data['Concussion']=full_data['Concussion'].fillna('False')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c6efa1f18e926356d07c75a693a22c978a4c6ffa"},"cell_type":"code","source":"full_data.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1ebf452495eef49c4de4cd25ad4590d3a52b555e"},"cell_type":"code","source":"#Because the 'YardLine' field reports numbers on the 0-50-0 scale of a football field, I did a little manipulation to be able to show where the play orinigated on one axis\n\nfull_data['starting_yard'] = full_data['YardLine'].str.extract('(\\d+)')\nfull_data['starting_yard'] = full_data['starting_yard'].map(int)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"39bbe70cc9c40c0559d2865dfb932c851d0a9ac1"},"cell_type":"code","source":"def yardline (row):\n    if row['Territory'] == 0:\n        return row['starting_yard']\n    if row['Territory'] == 1:\n        return 100-row['starting_yard']\n\nfull_data['100yd'] = full_data.apply (lambda row: yardline (row), axis=1)\nfull_data.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6e8f114d0811b88b6b778de9290c5d4080a57eb2"},"cell_type":"code","source":"full_data.drop(columns='starting_yard')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"14bce36862129e3b978c75aeba733ac166065f35"},"cell_type":"code","source":"full_data.sort_values('100yd', ascending=False)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"37573393bf43ca6415cb05ec8bf45b422c91c876"},"cell_type":"markdown","source":"In 2016, the Niners punted from the Bears 31? That seems...ill-advised. \n\nBut cool, the funciton worked and now we can graph the punts and outcomes."},{"metadata":{"trusted":true,"_uuid":"b5f29814e3c274094b12d97af2f32a7ffdcb9809"},"cell_type":"code","source":"#It would also be helpful to encode a variable for whether or not the play resulted in a return, because it sure seems like returns are dangerous\n\ndef returned (row):\n    if row['fair_catch'] == 1:\n        return False\n    if row['Touchback'] == 1:\n        return False\n    if row['out_of_bounds'] == 1:\n        return False\n    if row['downed'] == 1:\n        return False\n    if row['distance'] == 0:\n        return False\n    return True\n\nfull_data['returned'] = full_data.apply (lambda row: returned (row),axis=1)        ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"88803d755776f06e5226e4ca119c44b08aa8583f"},"cell_type":"code","source":"full_data.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0eaba95478f89bb4461beaf1e31fa8dc05606191"},"cell_type":"code","source":"full_data.info()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"928eb0119b10f5359abe23ad1e213a7ecd5a46c1"},"cell_type":"markdown","source":"Now that we have the full set of play data, we're going to use Machine Learning to create a decision tree to parse this large dataset and help us visualize which types of punts result in Concussions and how we can try to influence safer outcomes from punt plays."},{"metadata":{"trusted":true,"_uuid":"86f1cfb36a6760796a674f67b4cd1f5965dd4c17"},"cell_type":"code","source":"from sklearn.tree import DecisionTreeClassifier","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"83491dc027d65f3e95dedaa8a630e7e5bc86502d"},"cell_type":"markdown","source":"Which variables should we focus on? I'm not going to include variables that we couldn't (or nearly couldn't) influence. \n\nFor instance, should we include the type of game? To what end? Are we going to ban punting in the postseason or tell teams not to practice it in the preseaon? That doesn't seem feasible or safe.\n\nScore? Temperature? Playing surface? Quarter of the game? How could we possible use those to generate better outcomes without fundamentally altering the game?\n\nSo, instead, let's focus on aspects of gameplay that could reasonably be changed by the scope of this exercise, the rules of the game."},{"metadata":{"trusted":true,"_uuid":"e59e79781da90f132362c6bfd33e9c62878cd4a6"},"cell_type":"code","source":"target_name = 'Concussion'\nfeats = ['Territory','fair_catch','Touchback','out_of_bounds','downed']\nX = full_data[feats]\ny = full_data[target_name]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"882b90a54e57af5879997b16a2ef3f2fb6a9940f"},"cell_type":"code","source":"import graphviz \nfrom sklearn.tree import export_graphviz\n\ntreeclf = DecisionTreeClassifier()\n\ntreeclf.fit(X, y)\ndot_data = export_graphviz(treeclf, out_file=None, feature_names=feats)\n\ngraph = graphviz.Source(dot_data)  \ngraph","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"c08a6c6b13d19258ce9349e23d03306a71ddfab4"},"cell_type":"markdown","source":"This provides some insights (*there were only two concussions on any plays that ended in a fair catch*), but the tree is overfit and difficult to read.\n\nLet's put some constraints on the model to control for overfitting."},{"metadata":{"trusted":true,"_uuid":"31e1a5ca3d545ce9c5e18f8efa14bdeb58b17dd2"},"cell_type":"code","source":"treeclf_light = DecisionTreeClassifier(min_samples_split=100, min_samples_leaf=100, max_depth = 7)\n\ntreeclf_light.fit(X, y)\ndot_data = export_graphviz(treeclf_light, out_file=None, feature_names=feats)\n\ngraph = graphviz.Source(dot_data)  \ngraph","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a68ee456721bbf85182151e62cbfb43c3151e629"},"cell_type":"markdown","source":"### Much Better\n\n#### Now we can clearly see, of the 36 concussions on punt plays in those two seasons (the 37th concussion was on a fake punt - - see below):\n\n - There were **0 concussions** on punts out of bounds\n - There were **0 concussions** on punts that went for a touchback\n - Only **2 concussions** were on plays involving a fair catch\n - Only ** 3 concussions** were on plays where the punt was downed without a return\n\n### And shorter distance punts were far more dangerous than longer distances.\n\n#### Punt distance between:\n - 0 and 47 yards: 18 concussions\n\n - 47 and 57 yards: 10 concussions\n\n - 57 and 61 yards: 5 concussions\n\n - 61+ yards: 1 concussion"},{"metadata":{"trusted":true,"_uuid":"3cd81328057e9b497e977758858b77270824e91c"},"cell_type":"code","source":"#What was the deal with that punt of 0 yards? It wasn't a punt at all. The concussion occurred on a fake.\n\nfull_data['PlayDescription'].loc[2749]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4752fbd073250d6718e4761cfccb1cdbef2d4e67"},"cell_type":"code","source":"#Going from the more simplistic classification based on the side of the field to look more closely at where the play originated by yardline\n\ntarget_name = 'Concussion'\nfeats = ['100yd','fair_catch','Touchback','out_of_bounds','downed']\nX = full_data[feats]\ny = full_data[target_name]\n\ntreeclf_light = DecisionTreeClassifier(min_samples_split=100, min_samples_leaf=100, max_depth = 4)\n\ntreeclf_light.fit(X, y)\ndot_data = export_graphviz(treeclf_light, out_file=None, feature_names=feats)\n\ngraph = graphviz.Source(dot_data)  \ngraph","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"bfb0a4182cb638bd17a2bf80bbf2ae425533de01"},"cell_type":"markdown","source":"26 of the 37 concussions originated inside of the 30 yard line because the incentives greatly favor teams taking a shot at returning the punt"},{"metadata":{"trusted":true,"_uuid":"91ac7797d28da2faf34e8516509378b1fe4fdd45"},"cell_type":"code","source":"#Adding a static variable for graphing purposes\nfull_data['punt'] = \"Punt\"","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"5362d4dd693c3fafa451c983582e000310e6b281"},"cell_type":"markdown","source":"With this variable, I can create all of the below graphs that show us the frequency of these outcomes by where the punt play starts on the field.\n\nThe x-axis is the yard line (where 60 is the opponent's 40, 70 is the opponent's 30, etc.)"},{"metadata":{"trusted":true,"_uuid":"f0884b1f35903d204aa57efa7449e1faab70bd74"},"cell_type":"code","source":"g = sns.catplot(x='100yd', y='Concussion', data=full_data,orient='h', height= 7, aspect = 2)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1d8248c67dece4b90bbc5c5fe6aeb696a1565e75"},"cell_type":"code","source":"#One bar\ng = sns.catplot(x='100yd', y='punt', data=full_data, hue='returned',orient='h', height= 7, aspect = 2, palette = 'Greys', alpha=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"636563915b1faa0fb5df1374cdd6bd5dbf7dbad7"},"cell_type":"code","source":"#Two bars (just for different visualization types)\n\ng = sns.catplot(x='100yd', y='returned', data=full_data,orient='h',height= 7, aspect = 2, palette='Blues')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"495e2be7a8c00bdd6d7b14d40eb3720892c93a29"},"cell_type":"code","source":"g = sns.catplot(x='100yd', y='punt', data=full_data,orient='h', hue='fair_catch',height= 7, aspect = 2, palette='Blues', alpha=.8)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d4c009ab9aee81218cd79c8204d130e8e4a5522c"},"cell_type":"code","source":"#Two bars (just for different visualization types)\n\ng = sns.catplot(x='100yd', y='fair_catch', data=full_data,orient='h',height= 7, aspect = 2, palette='Blues')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"c36fe20df3308ac5d80473531f6d92a87a6ef852"},"cell_type":"markdown","source":"Finally, some breakdowns to aid with the potential impact of any rule changes"},{"metadata":{"trusted":true,"_uuid":"99d4c5a8fb61d32a49183be158e88ec1a2e3be2a"},"cell_type":"code","source":"full_data['downed'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0ebc16f15cce72776f63d80279537580d55d07fc"},"cell_type":"code","source":"full_data['fair_catch'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"19cf27de1f28fb10125f4995fe5a32e1037df847"},"cell_type":"code","source":"full_data[full_data['100yd']<31].fair_catch.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d90c7bca6d230939107b3605269fdf5a18ef41c2"},"cell_type":"code","source":"full_data[full_data['100yd']<31].downed.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5749ae2cb3f8889dae4fae878044526bff30c3e1"},"cell_type":"code","source":"full_data[(full_data['100yd']<31) & (full_data['fair_catch']==True)]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"80400446676de6a797dc8ea78bb44fc13a2a425a"},"cell_type":"code","source":"full_data[full_data['100yd']<31].distance.mean()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"925abb85706377df25505f3d629de68da4952f92"},"cell_type":"code","source":"full_data[full_data['100yd']<31].returned.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7748c1895edac9ad9cd945c4a8a7656b0b303550"},"cell_type":"code","source":"full_data.returned.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"967ac8968ae0aa7b981ebdc32de6dd3195e66da1"},"cell_type":"code","source":"full_data.groupby('returned')['100yd'].mean()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"28eb2318d656f724a72055588b73668ee45a031f"},"cell_type":"code","source":"full_data.groupby('returned')['100yd'].median()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6d2121a21efcc2f3596549ac5c440620ea7ddd1b"},"cell_type":"code","source":"full_data.groupby('fair_catch')['100yd'].mean()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2bd4892adc510e0432b0551623f101ab236c50b3"},"cell_type":"code","source":"full_data.groupby('fair_catch')['100yd'].median()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e922c9d654eed70be97a8b3e8ce9576d16138537","scrolled":true},"cell_type":"code","source":"g = sns.catplot(x='100yd', y='punt', data=full_data, hue='out_of_bounds',orient='h', height= 7, aspect = 2,palette = 'Greens')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ca007e4b4b7da4e58e2e53557a5b16b4ffd2d568"},"cell_type":"code","source":"g = sns.catplot(x='100yd', y='out_of_bounds', data=full_data,orient='h',height= 7, aspect = 2, palette='Greens')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"04264c20c18badc0fc504997254774f3407a7164"},"cell_type":"code","source":"g = sns.catplot(x='100yd', y='punt', data=full_data, hue='downed',orient='h', height= 7, aspect = 2,palette = 'Reds')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1c99cf4f2e0b65ed9105c869f1f69041a71494ea"},"cell_type":"code","source":"g = sns.catplot(x='100yd', y='downed', data=full_data,orient='h',height= 7, aspect = 2, palette='Reds')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"42cb02d81d33823e8b315056c985e893c02f3674"},"cell_type":"code","source":"g = sns.catplot(x='100yd', y='punt', data=full_data, hue='Touchback',orient='h', height= 7, aspect = 2,palette = 'Purples')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1040347f07f751366ace0e800481d4929a1d9dbc"},"cell_type":"code","source":"g = sns.catplot(x='100yd', y='Touchback', data=full_data,orient='h',height= 7, aspect = 2, palette='Purples')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5781f2fd77981246689c3c345e31c5081f084082"},"cell_type":"markdown","source":"# Conclusion\n\nSeveral things are clear:\n\n - Returns are dangerous\n - More punts are returned when the punt starts inside the 30\n - Fair catches are a safer outcome on the play and fewer fair catches happen on punts inside the 30\n - The rule change has to decrease the number of live returns and incentivize fair catches could be a good way to do that\n \n ## Proposed rule changes are included in the attached slide deck"},{"metadata":{"trusted":true,"_uuid":"4deb25fb30023ea7817298f1c6e44542d3bab5dd"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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}