{"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":"# 2022 NFL Big Data Bowl\n\nEDA and predicted return yards for punt plays\n\nBy: Luis Magana\n\nCode: https://github.com/maganowsky/BigDataBowl2022","metadata":{}},{"cell_type":"markdown","source":"**Introduction**:\n\nCoaches often say that special teams are as important as the other two facets of the game, however to this day we dont know as much as special teams as we like to think. Football analytics have revolutionized the game in recent years,every sunday there is a courageous coach going for it on 4th down and an oldschool analyst yelling at the TV for the \"innecessary agresiveness\". But what happens when a coach decides to not go for it? Till this date we have few tools to evaluate what happens once the punter gets in the field. This year BDB is here to change that.\n\n**Punting**:\n\nPunting is one little explore facet of the game, till this day the only revelant metric is shown is average punt yards for kickers and average return yards for returners. With this analysis i plan to explore a little bit more in detail what happens on punt plays, and then using tracking data and PFF scouting data for every play build a simple linear model to predict the expected return yards a fielder should get at the moment the ball is caught.","metadata":{}},{"cell_type":"markdown","source":"## Kickoff and Punt differences ##\n\nFirs i will explore the differences in each special teams kick, lets start explorint the distance each kick travel\n\n![whatever](https://raw.githubusercontent.com/maganowsky/BigDataBowl2022/ccbafac8698950b269c09f9a7c03889341c5f604/ImagesBDB/image0BDB.png)\n\n\nWe can see that the distribution of kickoffs is very left skewed which make sense since kickoff is much more consistant since its always kicked from the same spot and travles similar distances. We can see that punts in particular are much more normal distributed.\n\n\n**Now lets check what happens with the returns**\n\nWe're gonna plot the return yards for kickoffs and punts to see how this distributions compare\n\n  ![Returnyards](https://raw.githubusercontent.com/maganowsky/BigDataBowl2022/ccbafac8698950b269c09f9a7c03889341c5f604/ImagesBDB/image1.png)\n  \nWe can see an obvious difference, the distrubution of return yards in kickoffs is much more narrow and concentrated between 20 and 25 yds which again make sense since most kickoffs are kicked in the same conditions. Very different from the punt distribution, where there is much more randomness and therefore the distribution is more spread \n\n\n**Hang Time**\n\nOne of the main attributed a good punter has is the hangtime of his kicks, since this gives more time for the kicking team to get to the returner and prevent a big play. Thanks to the PFF data we have data on how the ball was kicked at the moment of the punt. We have thee types of kick contacts for punts\nN: Normal - standard punt style\nR: Rugby style punt\nA: Nose down or Aussie-style punts\n\nHow does the hang time vary for kicktype?\n\n![](https://raw.githubusercontent.com/maganowsky/BigDataBowl2022/ccbafac8698950b269c09f9a7c03889341c5f604/ImagesBDB/image2.png)![](https://raw.githubusercontent.com/maganowsky/BigDataBowl2022/ccbafac8698950b269c09f9a7c03889341c5f604/ImagesBDB/image3.png)    \n\nThe results are very similar but we can see that the distribution of \"Aussie\" style kicks is much more narrow\n\n\n","metadata":{}},{"cell_type":"markdown","source":"## Building our Model ##\n\nWe have data of the last 3 seasons, including play by play info, scout info provided by PFF (including formation, numer of gunners, kick hang time, etc) and also tracking data for each one of this plays. This means the position of evey player at every \"frame\" that the play is developed. \n\n**Objective**\n\nWith al this information we will try to develop a model that predicts the return yards a set returner is expected to get at the moment he catches the football. We will use a set of static features and also do some feature engineering to calculate two dynamic fields that will be returner distance to closest sideline at the moment of the catch and distance to closer defender at the moment of the catch.\n\nFeatures:\n* Kick Lenght \n* snap Time\n* yard line number ( Yard line at line-of-scrimmage )\n* absolute yard line number ( Location of ball downfield in tracking data coordinates)\n* Hang Time\n* Operation Time ( Timing from snap to kick on punt plays in seconds)\n* Snap Detail (whether the snap was on target and if not, provides detail (H: High, L: Low, <: Left, >: Right, OK: Accurate Snap))\n* yards to go (Distance needed for a first down)\n* distance to closest defender\n* distance to closest sideline\n\n\nThis is the initial set of features that was used to set the model, of course we can use more sophisticated features, but this is an initial approximation\n\n**Results**\n\nThe model is fitted using data from the last 3 seasons using punt plays that were returned (1880 plays in total) and using a simple linear regression.**The Mean Average Error we get is 6.2 yds** which is not terrible. One benefit of using a simple model like a linear regression is that we can interpret the results better. Here are the coefficients of the regression and therefore the feature importance according to the model (We scaled the data to get the feature importance regardless of measurement unit)\n\n![](https://raw.githubusercontent.com/maganowsky/BigDataBowl2022/ccbafac8698950b269c09f9a7c03889341c5f604/ImagesBDB/image4.png)\n\nIt makes sense that the top features are related to the distance the kicked travel, the closer defende and the hang time\n\nHowever our prediction has a problem, and is that its very hard to capture the entire variance of a punt return, lets check a comparison on our prediction against the actual values and their distribution\n\n\n![](https://raw.githubusercontent.com/maganowsky/BigDataBowl2022/ccbafac8698950b269c09f9a7c03889341c5f604/ImagesBDB/image5.png)\n\nHere in Blue we can see the actual values, and in orange our prediction, so basically our model has no way to explain a 20> yards return\n","metadata":{"execution":{"iopub.status.busy":"2022-01-06T05:24:22.341675Z","iopub.execute_input":"2022-01-06T05:24:22.342555Z","iopub.status.idle":"2022-01-06T05:24:22.365573Z","shell.execute_reply.started":"2022-01-06T05:24:22.342384Z","shell.execute_reply":"2022-01-06T05:24:22.364734Z"}}},{"cell_type":"markdown","source":"## Return Yards Over Expected ##\n\nOne of the benefits on having this model, its that we can evaluate the yards that a particular returner is gaining over the expected (What the model predicted). This metric can help us to evaluate returners since we can explain the difference between the expected yards and the actual yards with the returner skill.\n\nHere are the best returners of the last 3 seasons ant the worst ones (minimum 10 returns)\n\n![](https://raw.githubusercontent.com/maganowsky/BigDataBowl2022/ccbafac8698950b269c09f9a7c03889341c5f604/ImagesBDB/image6.png)                          \n\n![](https://raw.githubusercontent.com/maganowsky/BigDataBowl2022/ccbafac8698950b269c09f9a7c03889341c5f604/ImagesBDB/image7BDB.png)  ","metadata":{}},{"cell_type":"markdown","source":"## Conclusion ##\n\n\nWe can see that this analysis even if its pretty basic its very inline with other more advanced notebooks in this year competition. We can see that Nyheim Heines has been the best punt returner over the last couple of yeards. Also we can see that a good returner can bring 6 to 3 yards over the expected on each return, in a game of inches like football this little advantages can be huge down the stretch. \n\nAlso we see that some of the worst returners are receivers (Tavon Austin, Ceedee Lamb, Humphries, Locket) it can be that receivers that are also returning punts want to constantly push for the home run, this will make them dance around more before commitign a vertical lane of return or can make them field punts that should have been fair caught.\n\nThanks Michael Lopez and the rest of the NFL team for this amazing competiton\n\n","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}}]}