---
title: "Valuing Blocking on Kick Return Plays"
author: "Conor Malone"
date: "NFL Big Data Bowl 2022"
runtime: shiny
output:
  html_document:
    number_sections: true
    fig_caption: true
    toc: true
    theme: readable
    highlight: tango
---
   

  
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Introduction
                              
[Github Code](https://github.com/conormalone/BDB22)

Kick returning is the one of the most electric part of football, a player catches the ball, he runs into a mass of players and suddenly a gap appears and before you know it he makes it all the way to the endzone! 

![Duvernay Return](
https://i.imgur.com/0t8RlCJ.mp4) 

This return is from the 2020 season, where Baltimore's Devin Duvernay returns a kickoff 92 yards for a touchdown:
But how much of the yardage from this return is down to the kick returner’s skill and how much to his team-mates blocking defenders to clear his path?

I have taken a two pronged approach to valuing these blocks:
Firstly I have created an Expected Return Yards model to assess how far a returner is expected to carry the ball before play ends, 
by looking at player’s relative positions and speed.
From this I have derived Blocking Added Yards, looking at each play and assessing how many yards every other player on the returning team contributes to the return by calculating the expected return yards with and without their presence.

# The Models

## Expected Return Yards

My model uses a Graph Neural Network to predict yards gained on every punt and kickoff return at the point the kick is received and when the nearest potential tackler changes
For the 21 nearest players to the ball it knows their speed and their distance to every other player and their role (blocking, returning or tackling) and special team type (kickoff or punt)

## Expected Yards Added by Blocking

For every instance in the data 10 additional graphs of 21 players are prepared, where each returning player besides the ball carrier is omitted in turn.
The Expected Return Yards model is then used to predict how far the returner would get if each blocker was not present and these are compared to values with the full team present to get a yards value per blocking player.

# Inputs 

## The Data

Data comes from National Football League Next Gen Stats; positional and speed data is collected ten times per second from every player and the ball.
The dataset consists of 5079 kick return plays, which I converted to 13663 graph instances: meaning a snapshot is taken where ever a kick is received or the nearest tackler to the returner changes.
As there are potentially multiple instances on the same play the test/train split is done on plays, not instances.
Each graph contains 21 players, the furthest player from the returner is omitted in training.

## Graphs

Graphs are a unique way of ordering data, with a structure distinct from dataframes. Graphs have node (or vertex), edge, and graph level features.
For every instance in the data a graph was created consisting of the following:

### Nodes

Nodes refer to the connected points in the graph, in this case representing the players on the field. 
Our node features are:
Role (Returner, Blocker or Tackler)
Speed (in yards per second)
Play Type (Kick-off or Punt)

### Edges

Edges refers to the connections between the nodes, in this case every player is connected and the distance to every other node is a feature of the edges.

### Graph Level

This is an overall feature of each graph not tied to any node or edge: the graph level feature of this graph is return distance in yards, 
this is the feature that our model will predict.

The below image represents how the data is structured between 3 of the 21 players in each graph

![Graph Representation](
https://i.imgur.com/eFzalty.png) 

## The Model

Graph Neural Networks (GNNs) are a class of deep learning methods designed to perform inference on data described by graphs [1](https://arxiv.org/abs//1806.01261)

While Convolutional Neural Networks are commonly used for image classification they have had notable successful in other fields including predicting yardage on NFL plays, 
used in the [1st place Big Data Bowl 2020](https://www.kaggle.com/c/nfl-big-data-bowl-2020/discussion/119400) entry for Dmitry Gordeev and Philipp Singer (The Zoo)

The model uses a Graph Convolutional Network [2](https://arxiv.org/abs/1609.02907), which combines GNNs and CNNs, to classify a kick return into ordered classes from -20 to 100 return yards, similar to the output on Big Data Bowl 20.



# Results

## Model Performance 

The model has a mean absolute error of 0.05 on test data.

## Returners

Let's return to the good return from the start, Here is a gif of that best valued return in the set, Devin Duverney of the Ravens, predicted to go for 11 yards, went 92. 
The short predicted yardage probably indicates that the model expected Duvernay to be tackled by Kansas number 23, Armani Watts.

![Duvernay Return Dots](
https://i.imgur.com/xrATjQY.gif) 

Here is a chart of the best returners over expected

![Best Returners](https://i.imgur.com/Bxtdc8q.png)        


filled with household names this matches what we would expect, as only an actively bad model (or indeed a perfect model) would under-rate the best returners. 

## Blockers

The animation below shows (at half speed) a Kansas return against Denver in 2018, the actual return was 20 yards, with an expected return yards of 25, 
the block of Chiefs 51 Frank Zombo (starting between the hash marks) is credited with 24 yards of this return as without his presence there is a predicted return of only 1 yard.

the second graphic shows how Zombo's Expected Yards Added changes as the play develops

![Zombo Block](https://i.imgur.com/ZzqoxZT.gif) 

![Zombo Block Development](https://i.imgur.com/8Dwr2Hc.gif)     

As you can see Zombo's Expected Yards Added by Blocking decreases as the play goes on and the returner moves past him. 

The Best Blockers on Average (with over 25 plays) for each of the three seasons in the dataset are listed below:
    
![Best Blockers](https://i.imgur.com/SYsHQjo.png)

# Future Applications

## Assessing Fair Catches

This model could also be used to judge the wisdom of fair catch decisions: by predicting yards available to run we could assess which teams and players are leaving the most yards
behind where FC calls are concerned.
Currently it appears that the NFL NGS data doesn’t indicate where a fair catch is called (against the catch being made) so a model would need to be trained on based on the time before a catch.
Obviously fc decisions factor in more than just yards available, there is whether a player might turnover the ball or someone might get injured.

## Non-Special Teams play

This method, while developed for evaluating blocking on kick returns, has obvious applications to run protection on offensive plays to identify the players providing the best run protection and to quantify that value

