Transition Effectiveness

Beginner 10 min read 0 views Nov 27, 2025
# Overview Measure counter-attacking efficiency by analyzing transition speed, player involvement, and conversion rates. ## Python Implementation ```python import pandas as pd import numpy as np import matplotlib.pyplot as plt # Load transition events transitions = pd.read_csv('transitions.csv') # Calculate counter-attack metrics counter_attacks = transitions[transitions['type'] == 'counter_attack'] # Transition speed analysis counter_attacks['duration'] = counter_attacks['end_time'] - counter_attacks['start_time'] counter_attacks['speed'] = counter_attacks['distance_covered'] / counter_attacks['duration'] # Group by outcome transition_stats = counter_attacks.groupby('outcome').agg({ 'event_id': 'count', 'duration': 'mean', 'speed': 'mean', 'players_involved': 'mean', 'passes': 'mean' }).rename(columns={'event_id': 'count'}) print("Counter-Attack Analysis by Outcome:") print(transition_stats) # Success rate by duration counter_attacks['duration_bin'] = pd.cut(counter_attacks['duration'], bins=[0, 5, 10, 15, 30], labels=['0-5s', '5-10s', '10-15s', '15s+']) success_by_speed = counter_attacks.groupby('duration_bin').agg({ 'event_id': 'count', 'goal': 'sum', 'shot': 'sum' }) success_by_speed['goal_rate'] = (success_by_speed['goal'] / success_by_speed['event_id']) * 100 success_by_speed['shot_rate'] = (success_by_speed['shot'] / success_by_speed['event_id']) * 100 # Visualize fig, ax = plt.subplots(1, 2, figsize=(14, 5)) ax[0].bar(success_by_speed.index, success_by_speed['goal_rate'], color='green', alpha=0.7) ax[0].set_title('Goal Rate by Counter-Attack Duration') ax[0].set_ylabel('Goal Rate (%)') ax[0].set_xlabel('Duration') ax[1].bar(success_by_speed.index, success_by_speed['shot_rate'], color='blue', alpha=0.7) ax[1].set_title('Shot Rate by Counter-Attack Duration') ax[1].set_ylabel('Shot Rate (%)') ax[1].set_xlabel('Duration') plt.tight_layout() plt.show() ``` ## R Implementation ```r library(dplyr) library(ggplot2) library(gridExtra) # Load transition data transitions <- read.csv("transitions.csv") # Filter counter-attacks counter_attacks <- transitions %>% filter(type == "counter_attack") %>% mutate( duration = end_time - start_time, speed = distance_covered / duration ) # Analyze by outcome transition_stats <- counter_attacks %>% group_by(outcome) %>% summarise( count = n(), avg_duration = mean(duration), avg_speed = mean(speed), avg_players = mean(players_involved), avg_passes = mean(passes), .groups = "drop" ) print("Counter-Attack Analysis by Outcome:") print(transition_stats) # Success rate by duration counter_attacks <- counter_attacks %>% mutate(duration_bin = cut(duration, breaks = c(0, 5, 10, 15, 30), labels = c("0-5s", "5-10s", "10-15s", "15s+"))) success_by_speed <- counter_attacks %>% group_by(duration_bin) %>% summarise( total = n(), goals = sum(goal), shots = sum(shot), goal_rate = (goals / total) * 100, shot_rate = (shots / total) * 100, .groups = "drop" ) # Visualize p1 <- ggplot(success_by_speed, aes(x = duration_bin, y = goal_rate)) + geom_bar(stat = "identity", fill = "green", alpha = 0.7) + labs(title = "Goal Rate by Counter-Attack Duration", x = "Duration", y = "Goal Rate (%)") + theme_minimal() p2 <- ggplot(success_by_speed, aes(x = duration_bin, y = shot_rate)) + geom_bar(stat = "identity", fill = "blue", alpha = 0.7) + labs(title = "Shot Rate by Counter-Attack Duration", x = "Duration", y = "Shot Rate (%)") + theme_minimal() grid.arrange(p1, p2, ncol = 2) ```

Discussion

Have questions or feedback? Join our community discussion on Discord or GitHub Discussions.