Chapter 21: Exercises - Win Probability Models
Overview
These exercises progress from basic win probability concepts to building complete WP systems with calibration and decision analysis.
Level 1: Fundamentals
Exercise 1.1: Game State Encoding
Create a function to encode game states into feature vectors.
Task: 1. Define the key features that affect win probability 2. Implement normalization for each feature 3. Handle edge cases (overtime, end of game)
Starter Code:
def encode_game_state(score_diff: int,
seconds_remaining: int,
yard_line: int,
down: int,
distance: int,
has_ball: bool) -> np.ndarray:
"""
Encode game state as feature vector.
Returns normalized features suitable for ML model.
"""
# Your code here
pass
Exercise 1.2: Simple Win Probability
Build a simple win probability model using score differential and time.
Task: 1. Use only score_diff and time_remaining as features 2. Fit logistic regression to historical data 3. Evaluate on held-out test set
Exercise 1.3: Win Probability at Game Start
Calculate the baseline win probability at game start based on team strength.
Task: 1. Use pregame point spreads to estimate win probability 2. Implement the conversion formula: WP = 1 / (1 + 10^(-spread/10)) 3. Validate against historical results
Level 2: Intermediate
Exercise 2.1: Feature Engineering
Create comprehensive features for win probability.
Task: 1. Implement interaction terms (score × time) 2. Create categorical indicators (red zone, trailing late) 3. Add timeout differential features
Exercise 2.2: Calibration Analysis
Evaluate and improve model calibration.
Task: 1. Calculate calibration curve (predicted vs. actual by bin) 2. Compute Expected Calibration Error (ECE) 3. Apply isotonic regression to improve calibration
Starter Code:
def calculate_calibration(predictions: np.ndarray,
outcomes: np.ndarray,
n_bins: int = 10) -> pd.DataFrame:
"""
Calculate calibration statistics.
"""
# Your code here
pass
Exercise 2.3: Win Probability Added
Calculate WPA for each play in a game.
Task: 1. Calculate WP before and after each play 2. Compute WPA = WP_after - WP_before 3. Identify the highest-WPA plays in the game
Level 3: Advanced
Exercise 3.1: Gradient Boosting WP Model
Build a gradient boosting win probability model.
Task: 1. Implement feature engineering pipeline 2. Train XGBoost or GradientBoosting classifier 3. Compare to logistic regression baseline 4. Analyze feature importance
Exercise 3.2: Fourth Down Decision Analyzer
Build a fourth-down decision analysis system using WP.
Task: 1. Calculate WP for each decision option (go, punt, FG) 2. Incorporate conversion and field goal probabilities 3. Recommend optimal decision 4. Calculate "break-even" conversion rate
Exercise 3.3: Live Win Probability Tracker
Build a system to track WP throughout a game.
Task: 1. Process play-by-play data in order 2. Calculate WP after each play 3. Identify key momentum swings 4. Generate game WP chart
Level 4: Expert
Exercise 4.1: Complete WP System
Build an end-to-end win probability system.
Requirements: - Data preprocessing pipeline - Multiple model options (logistic, GBM, neural network) - Calibration module - WPA calculation - Visualization dashboard
Exercise 4.2: Contextual WP Adjustments
Implement adjustments for specific game contexts.
Task: 1. Home field advantage adjustment 2. Weather impact modeling 3. Altitude/environment factors 4. Team-specific strength adjustments
Project: Real-Time Win Probability System
Build a complete real-time WP tracking and analysis system.
Requirements
- Data Ingestion: Process live play-by-play data
- Model Inference: Real-time WP predictions
- WPA Tracking: Cumulative WPA for players/teams
- Decision Analysis: Fourth-down recommendations
- Visualization: Live WP chart and key play highlights
Deliverables
- Working prediction system
- Calibration analysis
- Historical validation
- Documentation