python案例怎么看两队的战术纪律性对比?

wen python案例 1

Python案例:两队战术纪律性对比分析

战术纪律性可以从多个维度量化,下面给你一个完整的分析框架和代码案例。

python案例怎么看两队的战术纪律性对比?

战术纪律性的量化指标

维度 具体指标 说明
防守纪律 犯规数、黄牌、红牌、越位 越低越有纪律
位置纪律 阵型保持度、球员位置偏移 越稳定越好
传球纪律 传球成功率、失误率、冒险传球占比 反映执行教练意图
跑动纪律 高强度跑动占比、无效跑动 战术执行度
进攻纪律 射门选择、进攻节奏一致性 是否按战术打

完整代码案例

数据准备(模拟数据)

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from math import pi
# 设置中文显示
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
# 模拟两队数据
data = {
    '指标': ['犯规次数', '黄牌数', '红牌数', '越位次数', 
             '传球成功率', '传球失误率', '阵型保持度', 
             '高强度跑动占比', '射门转化率', '防守站位评分'],
    'A队': [12, 3, 0, 4, 0.87, 0.13, 0.82, 0.68, 0.18, 8.2],
    'B队': [18, 5, 1, 7, 0.79, 0.21, 0.71, 0.55, 0.11, 6.8]
}
df = pd.DataFrame(data)
df['差值(B-A)'] = df['B队'] - df['A队']
print(df)

归一化处理(统一到0-1,越大越好)

def normalize(df, reverse_cols=None):
    """reverse_cols: 需要反向的列(越小越好,如犯规数)"""
    result = df.copy()
    for col in ['A队', 'B队']:
        col_min, col_max = df[col].min(), df[col].max()
        result[col + '_norm'] = (df[col] - col_min) / (col_max - col_min)
        # 反向指标
        if reverse_cols and col in ['A队', 'B队']:
            mask = df['指标'].isin(reverse_cols)
            result.loc[mask, col + '_norm'] = 1 - result.loc[mask, col + '_norm']
    return result
reverse_cols = ['犯规次数', '黄牌数', '红牌数', '越位次数', '传球失误率']
df_norm = normalize(df, reverse_cols)
print(df_norm[['指标', 'A队_norm', 'B队_norm']])

雷达图对比

categories = df['指标'].tolist()
N = len(categories)
angles = [n / float(N) * 2 * pi for n in range(N)]
angles += angles[:1]
fig, ax = plt.subplots(figsize=(9, 9), subplot_kw=dict(polar=True))
for team, color in [('A队', '#1f77b4'), ('B队', '#d62728')]:
    values = df_norm[team + '_norm'].tolist()
    values += values[:1]
    ax.plot(angles, values, 'o-', linewidth=2, label=team, color=color)
    ax.fill(angles, values, alpha=0.25, color=color)
ax.set_xticks(angles[:-1])
ax.set_xticklabels(categories, fontsize=11)
ax.set_title('A队 vs B队 战术纪律性雷达图\n(越靠外=纪律性越好)', size=14, pad=20)
ax.legend(loc='upper right', bbox_to_anchor=(1.3, 1.0))
plt.tight_layout()
plt.show()

综合纪律性评分

# 计算综合纪律性得分
df_norm['A队_得分'] = df_norm['A队_norm']
df_norm['B队_得分'] = df_norm['B队_norm']
score_A = df_norm['A队_得分'].mean()
score_B = df_norm['B队_得分'].mean()
print(f"A队综合战术纪律性得分: {score_A:.3f}")
print(f"B队综合战术纪律性得分: {score_B:.3f}")
print(f"胜者: {'A队' if score_A > score_B else 'B队'}")

分维度柱状图对比

fig, ax = plt.subplots(figsize=(12, 6))
x = np.arange(len(categories))
width = 0.35
ax.bar(x - width/2, df_norm['A队_norm'], width, label='A队', color='#1f77b4')
ax.bar(x + width/2, df_norm['B队_norm'], width, label='B队', color='#d62728')
ax.set_xticks(x)
ax.set_xticklabels(categories, rotation=30, ha='right')
ax.set_ylabel('归一化纪律性得分')
ax.set_title('各维度战术纪律性对比')
ax.legend()
ax.grid(axis='y', alpha=0.3)
plt.tight_layout()
plt.show()

文本结论输出

print("=" * 50)
print("战术纪律性对比结论")
print("=" * 50)
for _, row in df.iterrows():
    indicator = row['指标']
    a, b = row['A队'], row['B队']
    diff = b - a
    reverse = indicator in reverse_cols
    better = 'A队' if (diff > 0) == reverse else 'B队'
    print(f"{indicator}: A队={a} | B队={b}  →  {better}更优")
print("\n" + "=" * 50)
print(f"综合评分: A队={score_A:.3f}  B队={score_B:.3f}")

真实场景如何获取数据

数据源 用途
StatsBomb / Opta 详细事件数据(传球、跑位)
Wyscout 球员位置追踪
FBref / Understat 免费基础统计数据
SkillCorner / Metrica 位置追踪(阵型保持度)

示例:从 FBref 抓取

import requests
from bs4 import BeautifulSoup
# 获取比赛统计(示意)
url = "https://fbref.com/en/matches/xxxxx"
# 解析表格 → 提取犯规、黄牌、传球成功率等

进阶分析思路

  1. 位置纪律分析:用位置追踪数据计算球员平均站位偏移量(阵型松散度)

    # 每名球员位置标准差 → 越小越守纪律
    player_position_std = tracking_data.groupby('player')['x'].std()
  2. 传球网络分析:用 networkx 分析传球是否符合战术结构

    import networkx as nx
    G = nx.from_pandas_edgelist(pass_data, 'passer', 'receiver', 
                                 edge_attr='count')
    # 计算中心性 → 谁是战术核心
  3. 时间序列分析:纪律性在比赛不同阶段的变化

    df.groupby('time_period')[['犯规', '传球成功率']].mean().plot()

关键结论维度

分析完可以回答这些问题:

  • ✅ 哪队犯规更少、位置保持更好?
  • ✅ 哪队传球执行教练意图更彻底?
  • ✅ 哪队在落后时是否依然坚持战术?
  • ✅ 哪队的高强度跑动更有"性价比"?

需要我针对某个具体联赛/球队做实例分析,或者深入某个子模块(如传球网络、位置追踪)吗?

抱歉,评论功能暂时关闭!