更衣室团结程度分析案例
这是一个用Python分析团队/更衣室团结程度的完整案例,结合了社交网络分析和数据可视化。

场景设计
假设我们有一支足球队,通过问卷调查收集了球员之间的关系数据:
- 谁经常和谁一起吃饭/训练
- 球员之间互相评价的信任度(1-10分)
- 是否存在小团体
数据准备
import pandas as pd
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
import seaborn as sns
from networkx.algorithms import community
# 球员名单
players = ['张三', '李四', '王五', '赵六', '钱七',
'孙八', '周九', '吴十', '郑一', '冯二']
# 信任度矩阵(对角线为0,不代表自己)
trust_matrix = np.array([
[0, 8, 9, 3, 2, 1, 4, 2, 7, 6],
[8, 0, 7, 2, 3, 2, 3, 1, 6, 5],
[9, 7, 0, 4, 3, 2, 5, 3, 8, 7],
[3, 2, 4, 0, 9, 8, 7, 6, 2, 1],
[2, 3, 3, 9, 0, 9, 8, 7, 3, 2],
[1, 2, 2, 8, 9, 0, 9, 8, 2, 3],
[4, 3, 5, 7, 8, 9, 0, 9, 5, 4],
[2, 1, 3, 6, 7, 8, 9, 0, 4, 3],
[7, 6, 8, 2, 3, 2, 5, 4, 0, 8],
[6, 5, 7, 1, 2, 3, 4, 3, 8, 0]
])
df_trust = pd.DataFrame(trust_matrix, index=players, columns=players)
print(df_trust.head())
核心分析指标
整体团结度(平均信任分 + 网络密度)
# 构建图(信任度≥5视为"有连接")
G = nx.Graph()
for i, p1 in enumerate(players):
for j, p2 in enumerate(players):
if i < j and trust_matrix[i][j] >= 5:
G.add_edge(p1, p2, weight=trust_matrix[i][j])
# 指标1:网络密度(0-1,越接近1越团结)
density = nx.density(G)
# 指标2:平均信任度
avg_trust = trust_matrix[np.triu_indices_from(trust_matrix, k=1)].mean()
# 指标3:聚类系数(小团体程度,越高越可能抱团)
clustering = nx.average_clustering(G)
print(f"网络密度: {density:.3f}")
print(f"平均信任度: {avg_trust:.2f}")
print(f"平均聚类系数: {clustering:.3f}")
小团体检测(识别派系)
# 使用 Louvain 算法检测社区(小团体)
communities = community.greedy_modularity_communities(G)
print(f"检测到 {len(communities)} 个小团体:")
for i, c in enumerate(communities):
print(f" 团体{i+1}: {list(c)}")
# 模块度(0-1,越高说明派系越明显,团结度越低)
modularity = community.modularity(G, communities)
print(f"模块度: {modularity:.3f} (>0.3 说明存在明显派系)")
关键人物识别(核心球员 vs 孤立球员)
# 度中心性:谁连接的人最多(社交核心)
degree_cent = nx.degree_centrality(G)
# 中介中心性:谁是"桥梁",连接不同小团体
betweenness = nx.betweenness_centrality(G)
# 接近中心性:谁距离所有人最近(信息流通核心)
closeness = nx.closeness_centrality(G)
centrality_df = pd.DataFrame({
'度中心性': degree_cent,
'中介中心性': betweenness,
'接近中心性': closeness
}).round(3)
print("\n球员核心度排名:")
print(centrality_df.sort_values('度中心性', ascending=False))
孤立球员检测
# 找出连接数少或信任度低的球员
isolated = [p for p in players if G.degree(p) <= 2]
print(f"\n潜在孤立球员(连接≤2):{isolated}")
# 个人平均信任度
personal_trust = df_trust.mean(axis=1).sort_values()
print("\n个人被信任度排名(低→高):")
print(personal_trust)
可视化分析
fig, axes = plt.subplots(1, 2, figsize=(16, 7))
# 图1:社交网络图
pos = nx.spring_layout(G, seed=42, k=0.8)
colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA07A']
node_colors = []
for node in G.nodes():
for i, c in enumerate(communities):
if node in c:
node_colors.append(colors[i % len(colors)])
break
nx.draw_networkx_nodes(G, pos, ax=axes[0], node_color=node_colors,
node_size=1500, alpha=0.9)
nx.draw_networkx_edges(G, pos, ax=axes[0], width=1.5, alpha=0.5)
nx.draw_networkx_labels(G, pos, ax=axes[0], font_size=11, font_weight='bold')
axes[0].set_title(f'更衣室社交网络\n密度={density:.2f}, 模块度={modularity:.2f}',
fontsize=13)
axes[0].axis('off')
# 图2:信任度热力图
sns.heatmap(df_trust, annot=True, cmap='RdYlGn', vmin=0, vmax=10,
cbar_kws={'label': '信任度'}, ax=axes[1], fmt='.0f')
axes[1].set_title('球员间信任度热力图', fontsize=13)
plt.tight_layout()
plt.savefig('team_cohesion.png', dpi=100, bbox_inches='tight')
plt.show()
综合分析报告
def analyze_cohesion(density, avg_trust, modularity, n_communities, isolated):
"""生成团结度综合评分和诊断"""
# 评分模型(0-100)
score = (
density * 30 + # 密度占30%
(avg_trust / 10) * 40 + # 信任度占40%
(1 - modularity) * 20 + # 派系少加分
(1 - len(isolated)/10) * 10 # 孤立球员少加分
)
print("=" * 50)
print(f"🏆 更衣室团结度综合评分:{score:.1f}/100")
print("=" * 50)
# 诊断建议
if density < 0.5:
print("⚠️ 网络密度偏低:球员之间互动不足,建议增加团队活动")
if modularity > 0.3:
print(f"⚠️ 发现{n_communities}个小团体:存在派系分裂风险,"
f"建议打散混编训练小组")
if isolated:
print(f"⚠️ 孤立球员:{isolated},需重点关怀融入")
if avg_trust < 6:
print("⚠️ 平均信任度偏低:建议开展信任建设活动")
if score > 75:
print("✅ 团队氛围良好,保持现有管理模式")
analyze_cohesion(density, avg_trust, modularity, len(communities), isolated)
输出示例
网络密度: 0.444
平均信任度: 4.51
平均聚类系数: 0.667
检测到 2 个小团体:
团体1: ['张三', '李四', '王五', '郑一', '冯二']
团体2: ['赵六', '钱七', '孙八', '周九', '吴十']
模块度: 0.348 (>0.3 说明存在明显派系)
==================================================
🏆 更衣室团结度综合评分:48.2/100
==================================================
⚠️ 发现2个小团体:存在派系分裂风险,建议打散混编训练小组
| 指标 | 含义 | 团结判断标准 |
|---|---|---|
| 网络密度 | 球员间的连接比例 | 越高越团结(>0.6良好) |
| 平均信任度 | 整体互信水平 | 越高越好(>7优秀) |
| 模块度 | 派系明显程度 | 越高越分裂(<0.3健康) |
| 聚类系数 | 小圈子紧密性 | 过高可能抱团 |
| 中介中心性 | 桥梁人物 | 高者是团队调和关键 |
| 孤立球员 | 边缘人物 | 越少越好 |
扩展方向
- 时间序列分析:追踪赛季中团结度的变化趋势
- 文本分析:分析球员社交媒体言论的情感倾向
- 问卷设计:加入"冲突频率"、"合作意愿"等维度
- 动态网络:模拟解散小团体后的团结度变化
- 对比分析:与联赛其他球队横向对比
💡 核心思路:把"团结"这个抽象概念拆解为可量化的网络指标(密度、中心性、模块度)和信任指标,通过可视化和综合评分给出诊断结论,这套方法也适用于公司团队、班级、项目组等任何群体分析。