我注意到您问的是“这个python案例”,但您没有提供具体的案例内容,我可以根据您的问题,为您提供一个考虑密集赛程影响的Python分析框架示例。

以下是一个考虑密集赛程影响的球队表现分析示例,它通常出现在体育数据分析中:
import pandas as pd
import numpy as np
from datetime import datetime, timedelta
class FootballScheduleAnalysis:
"""
足球赛程密集程度分析器
考虑了比赛间隔天数对球队表现的影响
"""
def __init__(self, matches_df):
"""
:param matches_df: DataFrame包含以下列:
'date' - 比赛日期
'team' - 球队名称
'opponent' - 对手
'result' - 结果 (W/L/D)
'goals_for' - 进球数
'goals_against' - 失球数
'is_home' - 是否主场 (True/False)
"""
self.matches = matches_df.copy()
self.matches['date'] = pd.to_datetime(self.matches['date'])
self.matches = self.matches.sort_values('date')
def calculate_days_since_last_match(self, team):
"""
计算每场比赛距离上一场的间隔天数
"""
team_matches = self.matches[self.matches['team'] == team].copy()
team_matches['days_rest'] = team_matches['date'].diff().dt.days
# 赛季首场比赛设为14天(视为充足休息)
team_matches['days_rest'] = team_matches['days_rest'].fillna(14)
return team_matches
def classify_schedule_density(self, days_rest):
"""
将赛程密度分类:
0-3天: 密集赛程 (背靠背或超紧密)
4-6天: 中等密集
7+天: 充足休息
"""
if days_rest <= 3:
return 'dense' # 密集
elif 4 <= days_rest <= 6:
return 'medium' # 中等
else:
return 'adequate' # 充足
def analyze_density_impact(self):
"""
分析赛程密度对球队表现的影响
"""
results = []
for team in self.matches['team'].unique():
team_data = self.calculate_days_since_last_match(team)
team_data['density'] = team_data['days_rest'].apply(self.classify_schedule_density)
# 计算不同密度下的胜率
for density in ['dense', 'medium', 'adequate']:
subset = team_data[team_data['density'] == density]
if len(subset) > 0:
win_rate = (subset['result'] == 'W').mean()
avg_goals_for = subset['goals_for'].mean()
avg_goals_against = subset['goals_against'].mean()
results.append({
'team': team,
'density': density,
'matches': len(subset),
'win_rate': win_rate,
'avg_goals_for': avg_goals_for,
'avg_goals_against': avg_goals_against
})
return pd.DataFrame(results)
def team_density_comparison(self, team1, team2):
"""
比较两支球队在密集赛程下的表现差异
"""
analysis = self.analyze_density_impact()
t1 = analysis[analysis['team'] == team1]
t2 = analysis[analysis['team'] == team2]
print(f"\n=== {team1} vs {team2} 密集赛程对比 ===")
# 对比密集赛程下的表现
dense_comparison = pd.merge(
t1[t1['density'] == 'dense'],
t2[t2['density'] == 'dense'],
on='density',
suffixes=(f'_{team1}', f'_{team2}')
)
print("\n密集赛程(<=3天间隔)下表现对比:")
if not dense_comparison.empty:
dense_row = dense_comparison.iloc[0]
print(f" {team1}: 胜率{dense_row[f'win_rate_{team1}']:.1%}, 场均进{dense_row[f'avg_goals_for_{team1}']:.2f}球")
print(f" {team2}: 胜率{dense_row[f'win_rate_{team2}']:.1%}, 场均进{dense_row[f'avg_goals_for_{team2}']:.2f}球")
# 整体胜率对比(不考虑密度)
all_t1 = self.matches[self.matches['team'] == team1]
all_t2 = self.matches[self.matches['team'] == team2]
print(f"\n整体胜率:")
print(f" {team1}: {(all_t1['result'] == 'W').mean():.1%}")
print(f" {team2}: {(all_t2['result'] == 'W').mean():.1%}")
def fatigue_index_calculation(self):
"""
计算疲劳指数(考虑近30天比赛场次加权)
"""
reference_date = self.matches['date'].max()
days_window = 30
fatigue_data = []
for team in self.matches['team'].unique():
# 获取团队所有比赛
team_matches = self.matches[self.matches['team'] == team].copy()
for _, match in team_matches.iterrows():
# 计算该场比赛前30天内的比赛场次
window_start = match['date'] - timedelta(days=days_window)
prior_matches = team_matches[
(team_matches['date'] >= window_start) &
(team_matches['date'] < match['date'])
]
# 疲劳指数 = 最近30天比赛场次 / 该队平均比赛间隔
expected_days_between = 7 # 标准联赛通常7天一场
fatigue_score = len(prior_matches) * expected_days_between / days_window
# 加上距离上一场比赛的天数影响
days_since_last = match['days_rest'] if 'days_rest' in match else 7
rest_factor = min(days_since_last / 7, 1.0)
adjusted_fatigue = fatigue_score * (1 - rest_factor * 0.3)
fatigue_data.append({
'date': match['date'],
'team': team,
'fatigue_index': adjusted_fatigue,
'result': match['result'],
'is_home': match['is_home']
})
fatigue_df = pd.DataFrame(fatigue_data)
return fatigue_df
def density_correlation_analysis(self):
"""
相关性分析:赛程密度与比赛结果的关系
"""
# 准备数据集
all_with_density = []
for team in self.matches['team'].unique():
team_data = self.calculate_days_since_last_match(team)
team_data['density'] = team_data['days_rest'].apply(self.classify_schedule_density)
# 将分类变量转换为哑变量
density_dummies = pd.get_dummies(team_data['density'], prefix='density')
team_data = pd.concat([team_data, density_dummies], axis=1)
all_with_density.append(team_data)
combined = pd.concat(all_with_density)
# 简单相关性分析
numeric_cols = ['density_dense', 'density_medium', 'days_rest']
result_col = 'result'
# 将结果转换为得分(W=3, D=1, L=0)
combined['points'] = combined['result'].map({'W': 3, 'D': 1, 'L': 0})
# 计算相关系数矩阵
correlation_matrix = combined[numeric_cols + ['points']].corr()
print("=== 赛程密度与得分相关性分析 ===")
print(correlation_matrix)
# 额外的回归分析(简化版)
from scipy import stats
# 检查密集赛程是否显著影响得分
dense_points = combined[combined['density_dense'] == 1]['points']
normal_points = combined[combined['density_dense'] == 0]['points']
t_stat, p_value = stats.ttest_ind(dense_points, normal_points)
print(f"\n独立t检验(密集 vs 非密集):")
print(f" t统计量: {t_stat:.4f}")
print(f" p值: {p_value:.4f}")
print(f" 显著水平: {'显著影响' if p_value < 0.05 else '无明显统计学差异'}")
使用时的主要功能:
calculate_days_since_last_match()- 计算每场比赛的休息天数classify_schedule_density()- 将比赛分为密集/中等/充足休息analyze_density_impact()- 分析不同密度下的胜率和进球数据team_density_comparison()- 对比不同球队在密集赛程下的表现fatigue_index_calculation()- 建立疲劳指数模型density_correlation_analysis()- 进行统计显著性检验
典型应用场景:
- 评估球队是否在密集赛程中表现下滑
- 识别哪些球队更适应密集赛程
- 预测高强度赛事期(如圣诞赛程、欧冠加联赛)的表现
- 轮换策略的效果评估
如果您有具体的Python分析案例,请分享代码,我可以帮您检查它是否包含了密集赛程影响分析,并指出可能的改进空间。