Learn how to use Python to calculate fantasy football opportunity metrics.
If you have any questions about the code here, feel free to reach out to me on Twitter or on Reddit.
If you like Fantasy Football and have an interest in learning how to code, check out our Ultimate Guide on Learning Python with Fantasy Football Online Course. Here is a link to purchase for 15% off. The course includes 15 chapters of material, 14 hours of video, hundreds of data sets, lifetime updates, and a Slack channel invite to join the Fantasy Football with Python community.
In this part of the intermediate series, we are going to be talking about and introducing a new concept on the blog called WOPR, which stands for weighted opportunity rating. The goal of this post will be to find a way to measure receiver "opportunity" and find those player's who are getting the most "opportunity" on their respective offenses.
Measuring opportunity is vital in optimizing your roster for fantasy football. Simply put, if your players are not getting opportunities, then they are not going to score you points, and watching redzone on Sunday is going to be frustrating as hell. The key to winning consistently at fantasy football is to prioritize selecting, trading for, and picking up players who are consistently involved in their respective offenses. But what does being involved mean?
Air yards is the best measure we have in fantasy football of intent. Air yards are how far a ball went during a particular throw, regardless if it was caught or not. A player's total air yards for a given week is his average depth of target times times his number of targets that week. Later in this post, we'll look at the relationship between air yards and fantasy football performance using scipy.stats and matplotlib.
How can air yards help us measure opportunity? Well, a naive measure of measuring opportunity in fantasy football is to simply look at raw targets or targets per game. This approach simply isn't adequete enough when you consider a target near the line of scrimmage doesn't have the same amount of opportunity as a 50 yard bomb that could potentially be a 70 yard play. Adding air yards to the mix can help us account for this and come up with a more nuanced measure of fantasy football opportunity.
WOPR is defined as a weighted average of a player's target market share (their individual targets / team total targets for a particular week) and a player's air yard market share (an individual's air yards / team total air yards for a particular week).
WOPR = 1.5 * target_share + 0.7 * air_yards_share
In this post, we are going to be pulling NFL play by play data for the past 5 weeks and finding each player's WOPR for each week. We are going to also be throwing some matplotlib in to the mix and visualizing the relationship between air yards, yards after catch, and WOPR and receiving fantasy football points.
First things first, load up either a Google Colab notebook or jupyter ipynb notebook and import the libraries we'll need in the first cell.
Next, let's load in 2020 play by play data via nflfastR.
The next thing we need to do is to filter our DataFrame to only include pass plays and grab the relevant columns to our analysis. We're going to calculate the receiving fantasy points scored on each play, then groupby player id, player name, team, and week and consolidate the rows in to a weekly receiving stat line for each player.
From there, we'll use groupby again to find team targets and team team air yards, merge that with our weekly stat line DataFrame, and then calculate WOPR.
Next, let's look at the relationship between air yards, yards after catch, and WOPR and receiving fantasy points. We're going to be using the stats package to find the R^2 and using that as our plot titles.
As we can see here, WOPR was more predictive of fantasy football performance (0.746 R^2) than both yards after catch and air yards.
Finally, let's group by player and sum up their weekly WOPR to get a season-long WOPR number.
And there you have it, our top 30 receivers this year in terms of WOPR. These are the players that are receiving the most fantasy football opportunity this year (based on how we defined opportunity).
Some players here are unsurprising. Hollywood Brown receives a ton of air yards and probably a decent market share of his teams targets considering the Ravens don't have many receiving options.
One player that is a bit surprising and that has shown up two weeks in a row near the top of the list is Darius Slayton. Given last week's performance, it appears that Darius Slayton may be primed to finish as a WR3 this year, and maybe even WR2 if he becomes a bit more consistent.
Another player that has shown up 2 weeks in a row high up on this list is DJ Moore. He finally had his "breakout" game last Sunday, recording about 19 PPR fantasy points. The bulk of his fantasy points came on a 50+ yard touchdown that went 4 air yards.
|11907||(2:40) (Shotgun) 5-T.Bridgewater pass short left to 12-D.Moore for 57 yards, TOUCHDOWN.||4.0||57.0||1.0|
DJ Moore's usage is concerning for sure. He's getting a ton of air yards, but those high opportunity passes haven't really been catchable thus far. It looks like it might be the Robby Anderson show in CAR from now on.
Thanks for reading! Hopefully you found this analysis useful to your fantasy football team and more importantly, you were able to improve your pandas/python/matplotlib skills.