超级玩家
 
- 贡献度
- 0
- 金元
- 6323
- 积分
- 632
- 精华
- 0
- 注册时间
- 2013-11-30
|
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
# ==========================================
# 假设你已经有了 df_results (来自上一个脚本)
# 如果没有,这里手动模拟一点数据方便你演示逻辑
# ==========================================
# (如果你刚刚跑完了脚本,请注释掉下面这块模拟数据)
if 'df_results' not in locals():
data = {
'Activation': ['relu']*3 + ['tanh']*3 + ['logistic']*3,
'Hidden Nodes': ['(10,)', '(50, 50)', '(100, 100, 100)']*3,
'Test Acc': [0.95, 0.98, 0.99, 0.90, 0.92, 0.85, 0.88, 0.60, 0.50]
# 注意看 logistic 在深层网络(100,100,100)掉到了 0.5 (瞎猜水平)
}
df_results = pd.DataFrame(data)
# ==========================================
# 实验设计:可视化 "激活函数" 与 "隐藏层结构" 的相互作用
# ==========================================
# 1. 数据透视 (Pivot): 把长表变成矩阵
# index=行(Y轴), columns=列(X轴), values=颜色深浅(准确率)
pivot_table = df_results.pivot_table(index='Activation',
columns='Hidden Nodes',
values='Test Acc')
# 2. 绘制热力图
plt.figure(figsize=(10, 6))
sns.heatmap(pivot_table, annot=True, cmap='RdYlGn', fmt=".3f", vmin=0.5, vmax=1.0)
plt.title('Interaction Effect: Activation vs Network Structure')
plt.ylabel('Activation Function')
plt.xlabel('Hidden Layer Structure (Complexity)')
plt.show()
|
|