1 import numpy as np, matplotlib.pyplot as plt
   2 from _utils.plot_utils import setup_style, save_fig, PALETTE, COLORS
   3 setup_style()
   4 np.random.seed(42)
   5 
   6 models = {
   7     '本文模型 (AUC=0.952)': (0.952, 2.5),
   8     '随机森林 (AUC=0.921)': (0.921, 1.5),
   9     'SVM (AUC=0.887)': (0.887, 1.5),
  10     '逻辑回归 (AUC=0.845)': (0.845, 1.5),
  11 }
  12 
  13 fig, ax = plt.subplots(figsize=(6, 5.5))
  14 highlight_index = 0  # 重点系列的位置,与显示名称无关
  15 ax.grid(True, linestyle='--', alpha=0.15); ax.set_axisbelow(True)
  16 ax.plot([0,1],[0,1], '--', color=COLORS['ref_line'], linewidth=0.8, label='随机猜测')
  17 
  18 for i, (name, (auc, lw)) in enumerate(models.items()):
  19     fpr = np.sort(np.concatenate([[0], np.random.beta(1, auc*10, 50), [1]]))
  20     tpr = np.sort(np.concatenate([[0], np.random.beta(auc*10, 1, 50), [1]]))
  21     alpha = 1.0 if i == highlight_index else 0.6
  22     ax.plot(fpr, tpr, color=PALETTE[i], linewidth=lw, label=name, alpha=alpha, zorder=3)
  23 
  24 ax.set_xlabel('假阳性率 (FPR)', fontsize=11); ax.set_ylabel('真阳性率 (TPR)', fontsize=11)
  25 ax.set_xlim(-0.02, 1.02); ax.set_ylim(-0.02, 1.02)
  26 ax.legend(frameon=False, labelspacing=0.35, handlelength=1.6, fontsize=9, loc='lower right')
  27 ax.spines['top'].set_visible(False); ax.spines['right'].set_visible(False)
  28 fig.tight_layout()
  29 save_fig(fig, 'figures/fig_roc.pdf')