| license | apache-2.0 |
|---|---|
| title | nfl |
| sdk | docker |
| emoji | 🔥 |
| colorFrom | red |
| colorTo | indigo |
This project is based on a Kaggle competition focused on predicting player positions in the NFL after the quarterback releases the ball.
The challenge involves forecasting the next N frames (on an average 11) of movement for selected players using their past tracking data.
Player movement during a downfield pass is highly dynamic and uncertain — outcomes range from completions to interceptions. Understanding these trajectories helps the NFL analyze behavior of receivers, defenders, and passers during critical moments of a play.
During a pass play:
- The quarterback (QB) receives the snap.
- At the moment the ball is thrown, the prediction window begins.
- Tracking data provides positions and physical attributes for all players near the action.
- Not all 22 players are relevant — only those within the vicinity of the play (often 10–14 players).
Predict the next N (20–40) positions (x, y) for a subset of players (P_pred ≤ P) given:
- Their historical movement prior to the pass
- Ball landing location
- Player roles (Passer, Targeted Receiver, Defense, etc.)
- Game- and play-level context
Each frame includes tracking data before the pass is thrown:
game_id: Game identifier, unique (numeric)play_id: Play identifier, not unique across games (numeric)player_to_predict: Whether or not the x/y prediction for this player will be scored (bool)nfl_id: Player identification number, unique across players (numeric)frame_id: Frame identifier for each play/type, starting at 1 for each game_id/play_id/file type (input or output) (numeric)play_direction: Direction that the offense is moving (left or right)absolute_yardline_number: Distance from end zone for possession team (numeric) (how far from the score zone)player_name: Player name (text)player_height: Player height (ft-in)player_weight: Player weight (lbs)player_birth_date: Birth date (yyyy-mm-dd)player_position: Player's position (role on the field)player_side: Team player is on (Offense or Defense)player_role: Role on the play (Defensive Coverage, Targeted Receiver, Passer, Other Route Runner)x: Player position along the long axis of the field (0–120 yards)y: Player position along the short axis of the field (0–53.3 yards)s: Speed in yards/second (numeric)a: Acceleration in yards/second² (numeric)o: Orientation of player (degrees)dir: Angle of player motion (degrees)num_frames_output: Number of frames to predict in output data for the given game_id/play_id/nfl_id (numeric)ball_land_x: Ball landing x-position (0–120 yards)ball_land_y: Ball landing y-position (0–53.3 yards)
Feature engineering is performed using the NFLFeatureTransformer class, which normalizes numerical fields and adds several new features.
sin_dir,cos_dirsin_o,cos_oangle_between_ball_land_and_playerangle_between_ball_land_and_player_orientsin_angle_between_ball_land_and_playercos_angle_between_ball_land_and_playersin_angle_between_ball_land_and_player_orientcos_angle_between_ball_land_and_player_orientsin_change_in_ocos_change_in_ochange_in_dirsin_change_in_dircos_change_in_dirchange_in_oangle_between_orientation_and_player
These help the model understand relative direction and orientation with respect to the ball.
velocity_x,velocity_yacc_x,acc_ydistance_to_x,distance_to_ydistance_to_sideline,distance_to_ball_land_x,distance_to_ball_land_yabsolute_yardline_numberdistance_between_the_recieverdistance_between_the_passerdistance_to_defensedistance_to_defense_xdistance_to_defense_ydistance_to_offensedistance_to_offense_xdistance_to_offense_ynearest_teammate_disnearest_teammate_dis_xnearest_teammate_dis_y,required_velocity_xrequired_velocity_yrequired_acc_xrequired_acc_yproj_x_accproj_y_accproj_x_velocityproj_y_velocityrequired_speedrequired_acceleration
These features capture how players move in relation to the field and ball landing location.
time_leftrequired_speed,required_accelerationchange_in_x,change_in_ychange_in_speedchange_in_accelerationchange_in_ochange_in_dirproj_x_acc_diffproj_y_acc_diffproj_x_velocity_diffproj_y_velocity_diffrequired_speed_diffrequired_velocity_x_diffrequired_velocity_y_diffrequired_acc_x_diffrequired_acc_y_diff
These model short-term motion dynamics and evolution of movement.
gru.pylightGBT.py
Each python file represents a separate modeling approach to the same prediction task.
This approach combines:
- Takes the last given frame and uses that data to predict the next
num_frames_output. - We predict the residual from the last known x and y positions.
- Uses a separate model dx_model , dy_model to predict the residuals.
This approach combines:
Uses Two Models to find dx , dy from the last known x and y positions.
-
Spatial Encoder
- Operates on
[T, P, din] - Captures relationships among players at a given time frame
- Operates on
-
GRU Layer
- Operates on
[P, T, din] - Models temporal evolution for each player's trajectory (taken only on the players to predict)
- Takes cross attention with Spatial Encoder at each time t.
- Operates on
-
MLP Layer
- Operates on
[P*T, din] - outputs the change in displacment dx, dy
- Operates on
Input is fed as:
[P, T, din]
Where:
P: total players under focusT: total time stepsdin: input feature dimension
- Mean Squared Error (MSE)
- RMSE: 1.71 yards on physics first order linear exerpolation
- RMSE: 0.66 yards on LightGBT
- RMSE: 0.60 yards on RNN With Cross Attention and MLP
- Explore graph neural networks for player–player interaction modeling.
This project applies deep feature engineering, transformers, and recurrent architectures to model complex NFL player movement in pass plays.
The lightGBT approach is lot simpler and acheives slightly better performance.