Chapter 14: Exercises

Set Piece Analytics Practice Problems

These exercises progress from fundamental concepts to advanced implementations, providing hands-on experience with set piece analysis techniques.


Part 1: Corner Kick Analysis (Exercises 1-6)

Exercise 1: Basic Corner Statistics

Difficulty: Beginner

Using the StatsBomb open data, analyze all corners from a single match.

Tasks: 1. Load match events and identify all corner kicks 2. Calculate the total number of corners for each team 3. Determine how many corners resulted in shots within 10 seconds 4. Calculate the basic conversion rate (shots/corners) for each team

Starter Code:

from statsbombpy import sb
import pandas as pd

# Load match data
events = sb.events(match_id=8658)

# Your code here
# 1. Identify corner kicks
# 2. Calculate statistics

Expected Output: - Number of corners per team - Shots generated from corners - Conversion rate


Exercise 2: Corner Delivery Classification

Difficulty: Beginner

Classify corner kick deliveries by target zone and trajectory.

Tasks: 1. Extract corner kick pass end locations 2. Classify each corner by target zone (near post, central, far post, short) 3. Determine delivery trajectory (inswinger, outswinger) based on pass technique 4. Create a summary table of delivery types

Questions: - Which target zone is most common? - Is there a difference in target zone preference between teams? - What is the distribution of delivery trajectories?


Exercise 3: First Contact Analysis

Difficulty: Intermediate

Analyze who wins first contact from corner deliveries.

Tasks: 1. Identify aerial duels occurring within 3 seconds of corner delivery 2. Determine which team wins the first aerial duel 3. Track the location of first contact 4. Calculate win rate for attacking team

Expected Metrics: - Attacking team first contact win rate - Average location of first contact (x, y coordinates) - Distribution of contact points (heatmap data)


Exercise 4: Corner xG Calculation

Difficulty: Intermediate

Calculate expected goals generated from corner kicks.

Tasks: 1. Identify all shots occurring within 10 seconds of a corner 2. Sum the xG values for these shots 3. Calculate average xG per corner by delivery type 4. Compare actual goals to expected goals

Analysis Questions: - Which delivery type generates the highest xG per corner? - Are teams over- or under-performing their corner xG? - What is the total xG from corners vs. open play?


Exercise 5: Corner Routine Clustering

Difficulty: Advanced

Use unsupervised learning to identify distinct corner routine patterns.

Tasks: 1. Extract features for each corner (end location, delivery type, etc.) 2. Apply K-means clustering to group similar corners 3. Analyze the characteristics of each cluster 4. Determine which clusters produce the most goals/xG

Required Features: - End location (x, y) - Pass length - Delivery trajectory (encoded) - Height classification - Short corner indicator


Exercise 6: Season-Long Corner Analysis

Difficulty: Advanced

Analyze corner patterns across an entire competition.

Tasks: 1. Load all matches from a competition 2. Aggregate corner statistics by team 3. Identify teams with highest corner conversion rates 4. Analyze if conversion rate correlates with total corners

Deliverables: - Team ranking by corner effectiveness - Scatter plot: corners taken vs. goals from corners - Statistical analysis of corner efficiency


Part 2: Free Kick Analysis (Exercises 7-12)

Exercise 7: Free Kick Zone Classification

Difficulty: Beginner

Classify free kicks by their shooting potential.

Tasks: 1. Identify all free kicks in attacking positions (x > 80) 2. Calculate distance and angle to goal 3. Classify into shooting zones (prime, good, moderate, marginal) 4. Count free kicks in each zone

Zone Definitions: - Prime: 18-22m, central - Good: 22-28m, central - Moderate: 18-25m, wide - Marginal: 28-35m, any angle


Exercise 8: Direct Free Kick Conversion

Difficulty: Beginner

Analyze direct free kick shooting success.

Tasks: 1. Identify free kicks that resulted in direct shots 2. Calculate conversion rate by distance zone 3. Determine shot outcome distribution (goal, saved, missed) 4. Compare to open-play shot conversion at similar distances


Exercise 9: Free Kick Delivery Patterns

Difficulty: Intermediate

Analyze indirect free kick delivery patterns.

Tasks: 1. Identify indirect free kicks (passes from free kick situations) 2. Classify delivery type (cross, short, lay-off) 3. Track subsequent shot generation 4. Calculate xG by delivery pattern

Categories: - Direct cross into box - Short combination play - Lay-off for edge of box shot - Driven near post delivery


Exercise 10: Free Kick Specialist Identification

Difficulty: Intermediate

Identify the best free kick takers in a competition.

Tasks: 1. Aggregate free kick statistics by player 2. Calculate goals per direct free kick attempt 3. Calculate xG overperformance on free kicks 4. Rank players by free kick effectiveness

Metrics to Calculate: - Free kick attempts - Goals scored - xG from free kicks - Goals above expected


Exercise 11: Free Kick Model Building

Difficulty: Advanced

Build a custom xG model for direct free kicks.

Tasks: 1. Collect all direct free kick shots with outcomes 2. Engineer features (distance, angle, wall size if available) 3. Train a logistic regression model 4. Evaluate model performance with cross-validation

Features to Consider: - Distance to goal - Angle to goal - Shot technique - Match context (score, time)


Exercise 12: Free Kick Tactical Analysis

Difficulty: Advanced

Conduct opponent scouting for free kick tendencies.

Tasks: 1. Load multiple matches for a specific team 2. Analyze their free kick patterns (direct vs. indirect) 3. Identify key free kick takers 4. Map typical target zones for crosses 5. Generate scouting report


Part 3: Penalty Analysis (Exercises 13-18)

Exercise 13: Basic Penalty Statistics

Difficulty: Beginner

Calculate fundamental penalty statistics.

Tasks: 1. Identify all penalties in a dataset 2. Calculate overall conversion rate 3. Analyze outcomes (goal, saved, missed frame) 4. Compare to expected conversion rate (~76%)


Exercise 14: Penalty Placement Analysis

Difficulty: Beginner

Analyze penalty shot placement patterns.

Tasks: 1. Extract shot end locations for penalties 2. Classify into zones (top left, top right, bottom left, bottom right, center) 3. Calculate conversion rate by zone 4. Visualize placement distribution

Expected Insight: - Which zones have highest conversion? - What is the miss rate by zone? - Where do goalkeepers save most often?


Exercise 15: Goalkeeper Penalty Analysis

Difficulty: Intermediate

Analyze goalkeeper performance on penalties.

Tasks: 1. Identify penalty events faced by each goalkeeper 2. Calculate save rate 3. Analyze dive direction tendencies 4. Determine if goalkeepers have predictable patterns

Questions to Answer: - Which goalkeepers save above average? - Do goalkeepers favor one side? - Is there correlation between dive timing and save success?


Exercise 16: Penalty Taker Profiling

Difficulty: Intermediate

Build profiles for penalty takers.

Tasks: 1. Aggregate penalty data by taker 2. Calculate preferred foot influence 3. Map placement tendencies over time 4. Identify consistent vs. variable takers

Profile Elements: - Total penalties taken - Conversion rate - Preferred placement zones - Technique patterns


Exercise 17: Game Theory Simulation

Difficulty: Advanced

Simulate penalty outcomes using game theory.

Tasks: 1. Define a payoff matrix for taker and goalkeeper 2. Calculate mixed strategy Nash equilibrium 3. Simulate penalties using the equilibrium strategies 4. Compare simulated outcomes to actual data

Matrix Definition: - Taker choices: Left, Center, Right - Goalkeeper choices: Dive Left, Stay, Dive Right - Outcomes: Goal probability for each combination


Exercise 18: Penalty Shootout Analysis

Difficulty: Advanced

Analyze penalty shootout dynamics.

Tasks: 1. Load penalty shootout data 2. Analyze conversion rate by kick number 3. Test for pressure effects (must-score situations) 4. Model shootout win probability

Hypotheses to Test: - Does conversion rate decline as shootout progresses? - Do teams shooting first have an advantage? - How does match context affect conversion?


Part 4: Throw-in Analysis (Exercises 19-24)

Exercise 19: Throw-in Volume and Location

Difficulty: Beginner

Map throw-in occurrences in a match.

Tasks: 1. Identify all throw-in events 2. Classify by pitch zone (defensive, middle, attacking) 3. Calculate throw-ins per team per zone 4. Visualize throw-in locations


Exercise 20: Throw-in Retention

Difficulty: Beginner

Calculate possession retention from throw-ins.

Tasks: 1. Determine outcome of each throw-in (successful/unsuccessful) 2. Calculate retention rate by zone 3. Compare teams' throw-in effectiveness 4. Identify if zone affects retention


Exercise 21: Attacking Throw-in Analysis

Difficulty: Intermediate

Analyze throw-ins in the attacking third.

Tasks: 1. Filter to attacking throw-ins 2. Track whether shot resulted within 15 seconds 3. Calculate xG generated from attacking throw-ins 4. Compare long throws vs. short throws


Exercise 22: Long Throw Identification

Difficulty: Intermediate

Identify and analyze long throw-ins.

Tasks: 1. Calculate throw-in length for each event 2. Define long throw threshold (>30m) 3. Compare outcomes of long vs. regular throws 4. Identify players who take long throws

Questions: - What percentage of throw-ins are long throws? - How does shot rate compare? - Are long throws more effective?


Exercise 23: Throw-in Pattern Recognition

Difficulty: Advanced

Use clustering to identify throw-in patterns.

Tasks: 1. Extract features: location, direction, length, outcome 2. Apply clustering algorithm 3. Analyze cluster characteristics 4. Determine most effective pattern clusters


Exercise 24: Team Throw-in Style Analysis

Difficulty: Advanced

Compare team throw-in philosophies across a league.

Tasks: 1. Aggregate throw-in data by team 2. Calculate style metrics (long throw %, forward throw %) 3. Cluster teams by throw-in style 4. Analyze relationship between style and attacking output


Part 5: Defensive Set Piece Analysis (Exercises 25-30)

Exercise 25: Defensive Corner Statistics

Difficulty: Beginner

Analyze team defensive performance on corners.

Tasks: 1. Identify corners conceded 2. Track shots allowed from corners 3. Calculate goals conceded from corners 4. Compare to league average


Exercise 26: Aerial Duel Defense

Difficulty: Intermediate

Analyze aerial duel performance in defensive set pieces.

Tasks: 1. Identify aerial duels during opponent corners 2. Calculate team win rate 3. Identify key aerial defenders 4. Map defensive aerial wins


Exercise 27: Clearance Effectiveness

Difficulty: Intermediate

Evaluate clearance quality on set pieces.

Tasks: 1. Track clearances during defensive set pieces 2. Calculate clearance distance 3. Determine if clearances lead to continued attacks 4. Identify effective vs. weak clearances


Exercise 28: Defensive Vulnerability Mapping

Difficulty: Advanced

Identify defensive weaknesses from set pieces.

Tasks: 1. Map locations of goals conceded from set pieces 2. Analyze delivery types that cause problems 3. Identify player matchup issues 4. Generate vulnerability report


Exercise 29: Set Piece xGA Model

Difficulty: Advanced

Build expected goals against model for set pieces.

Tasks: 1. Calculate xG of shots faced from set pieces 2. Compare actual goals to xGA 3. Evaluate goalkeeper performance on set pieces 4. Identify teams over/under-performing defensively


Exercise 30: Comprehensive Set Piece Report

Difficulty: Expert

Create a complete set piece analysis report for a team.

Tasks: 1. Combine all attacking set piece metrics 2. Combine all defensive set piece metrics 3. Calculate net set piece differential 4. Generate visualizations for each category 5. Write executive summary with recommendations

Report Sections: - Executive summary - Attacking analysis (corners, free kicks, throw-ins) - Defensive analysis (corners, free kicks defended) - Player spotlight (key set piece performers) - Opponent scouting preview - Tactical recommendations

Deliverables: - PDF/HTML report - Visualization dashboard - Data tables with key metrics


Submission Guidelines

For each exercise: 1. Provide complete, documented code 2. Include output/results 3. Answer all analysis questions 4. Visualize data where appropriate

Assessment Criteria

  • Code Quality (25%): Clean, documented, efficient code
  • Analytical Depth (25%): Thorough exploration of the data
  • Insights Generated (25%): Meaningful conclusions from analysis
  • Visualization Quality (25%): Clear, informative graphics

Additional Challenges

Challenge A: Real-Time Set Piece Tracker

Build a live application that tracks set piece events and updates statistics in real-time.

Challenge B: Set Piece Prediction Model

Develop a model that predicts the outcome of a set piece given delivery and defensive setup.

Challenge C: Video Integration

Create a tool that links set piece events to video clips for analysis.

Challenge D: Opposition Report Generator

Build an automated system that generates opponent set piece scouting reports.