python案例怎么看两队后防默契度差异?

wen python案例 2

用Python分析两队后防默契度差异

后防默契度是一个综合性指标,可以从传球网络、协防数据、失误率、位置同步性等维度量化,下面给你一套完整的分析框架和代码案例。

python案例怎么看两队后防默契度差异?

指标设计思路

维度 具体指标 说明
传球默契 后防球员间传球成功率、传球次数 传球越流畅说明配合越熟
协防能力 抢断+拦截+解围的联动 补位是否及时
位置同步 防线整体移动距离、越位造次数 造越位需要高度默契
稳定性 后防失误导致丢球、被过次数 失误越少越默契
阵容稳定 后防首发组合的出场时间 长期搭档默契更高

完整代码示例

构造数据(模拟真实比赛数据)

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
# 模拟两队后防球员的比赛数据
data = {
    'team': ['A队']*5 + ['B队']*5,
    'player': ['A1','A2','A3','A4','A5', 'B1','B2','B3','B4','B5'],
    'position': ['GK','LB','CB','CB','RB']*2,
    'passes':   [32, 45, 52, 48, 41,  28, 38, 44, 40, 35],       # 传球次数
    'pass_acc': [0.82,0.88,0.91,0.89,0.85, 0.78,0.83,0.86,0.84,0.80],  # 传球成功率
    'tackles':  [0, 3, 4, 5, 2,  0, 2, 3, 3, 2],                 # 抢断
    'intercept':[1, 2, 3, 3, 2,  0, 1, 2, 2, 1],                 # 拦截
    'clearance':[2, 4, 6, 7, 3,  1, 3, 4, 4, 3],                 # 解围
    'errors':   [0, 1, 0, 1, 1,  1, 2, 1, 2, 1],                 # 致命失误
    'minutes':  [900,880,900,850,900, 700,650,720,680,700]       # 出场时间
}
df = pd.DataFrame(data)
print(df)

归一化打分模型

from sklearn.preprocessing import MinMaxScaler
# 正向指标(越大越好):传球成功率、抢断、拦截、解围、出场时间
# 负向指标(越小越好):失误
scaler = MinMaxScaler()
pos_cols = ['pass_acc','tackles','intercept','clearance','minutes']
neg_cols = ['errors']
df_pos = pd.DataFrame(scaler.fit_transform(df[pos_cols]), columns=pos_cols)
df_neg = pd.DataFrame(1 - scaler.fit_transform(df[neg_cols]), columns=neg_cols)
# 权重(可根据业务调整)
weights = {
    'pass_acc': 0.30,
    'tackles':  0.15,
    'intercept':0.15,
    'clearance':0.10,
    'minutes':  0.15,
    'errors':   0.15
}
df['默契分'] = (
    df_pos['pass_acc']*weights['pass_acc'] +
    df_pos['tackles']*weights['tackles'] +
    df_pos['intercept']*weights['intercept'] +
    df_pos['clearance']*weights['clearance'] +
    df_pos['minutes']*weights['minutes'] +
    df_neg['errors']*weights['errors']
) * 100
team_score = df.groupby('team')['默契分'].mean().round(2)
print("队伍后防默契平均分:\n", team_score)

传球网络分析(核心:默契度最直观的体现)

import networkx as nx
import matplotlib.pyplot as plt
# 模拟A队后防球员之间的传球矩阵(行=传球者,列=接球者)
pass_matrix_A = pd.DataFrame([
    [0, 12, 15, 10, 8],   # A1 传给其他人
    [10, 0, 18, 14, 9],
    [12, 20, 0, 22, 15],
    [9, 15, 20, 0, 12],
    [7, 10, 14, 11, 0]
], index=['A1','A2','A3','A4','A5'], columns=['A1','A2','A3','A4','A5'])
pass_matrix_B = pd.DataFrame([
    [0, 8, 10, 7, 6],
    [7, 0, 12, 10, 6],
    [9, 13, 0, 15, 10],
    [6, 9, 14, 0, 8],
    [5, 7, 9, 8, 0]
], index=['B1','B2','B3','B4','B5'], columns=['B1','B2','B3','B4','B5'])
def plot_network(matrix, title, ax):
    G = nx.DiGraph()
    for i in matrix.index:
        for j in matrix.columns:
            if matrix.loc[i,j] > 0:
                G.add_edge(i, j, weight=matrix.loc[i,j])
    pos = nx.circular_layout(G)
    edges = G.edges(data=True)
    weights = [d['weight'] for _,_,d in edges]
    nx.draw(G, pos, ax=ax, with_labels=True, node_color='lightblue',
            node_size=800, width=[w/3 for w in weights],
            edge_color='gray', arrows=True, arrowsize=15)
    ax.set_title(title)
fig, axes = plt.subplots(1, 2, figsize=(12,5))
plot_network(pass_matrix_A, 'A队后防传球网络', axes[0])
plot_network(pass_matrix_B, 'B队后防传球网络', axes[1])
plt.tight_layout()
plt.show()

雷达图对比

from math import pi
metrics = ['传球成功率','抢断','拦截','解围','出场稳定性','低失误率']
def build_radar(df_team, team):
    sub = df[df['team']==team]
    return [
        sub['pass_acc'].mean(),
        sub['tackles'].mean()/5,
        sub['intercept'].mean()/5,
        sub['clearance'].mean()/8,
        sub['minutes'].mean()/900,
        1 - sub['errors'].mean()/3
    ]
angles = [n/len(metrics)*2*pi for n in range(len(metrics))]
angles += angles[:1]
fig, ax = plt.subplots(figsize=(6,6), subplot_kw=dict(polar=True))
for team, color in [('A队','steelblue'), ('B队','tomato')]:
    values = build_radar(df, team)
    values += values[:1]
    ax.plot(angles, values, color=color, linewidth=2, label=team)
    ax.fill(angles, values, color=color, alpha=0.2)
ax.set_xticks(angles[:-1])
ax.set_xticklabels(metrics)
ax.legend(loc='upper right', bbox_to_anchor=(1.3,1.1))'两队后防默契度雷达图对比')
plt.show()

结果解读示例

运行后你通常会得到类似结论:

队伍后防默契平均分:
A队    72.35
B队    54.18

分析要点:

  1. A队默契度更高:传球网络更密、协防数据更均衡
  2. B队短板:从雷达图看某个维度(如解围或稳定性)塌陷
  3. 位置差异:中卫(CB)传球网络中心度最高 → 是防线核心,若中卫更换频繁默契度会急剧下降

进阶建议(用真实数据)

数据源 可用字段
StatsBomb Open Data 逐次传球坐标、压力事件
FBref 后防四人组同时出场时间
Opta/SofaScore API 位置热图、越位次数

真实场景中可加上:

  • 防线整体移动熵:用球员x坐标标准差衡量平行度
  • 造越位成功率:成功造越位 / 尝试造越位
  • 后防组合共出场时长(如"范戴克+科纳特"组合 1200 分钟 → 默契值加分)

如果你想用真实比赛数据(比如指定某场英超/中超的两支队伍),告诉我比赛信息,我可以给你写适配 StatsBomb 或 FBref 的抓取代码。

上一篇这个python案例怎么看双方的心理素质对比?

下一篇当前分类已是最新一篇

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