MCPcopy Create free account
hub / github.com/LeMo-CtRes/CtRes / plot_sr_plus

Function plot_sr_plus

utils/utils_ode.py:468–532  ·  view source on GitHub ↗

绘制增强的结果图,包含多个指标: 1. 准确率(训练 & 测试) 2. 精确率 & F1 分数 3. 平均 ODE 积分时间 4. 分类器拟合 & 预测时间

(results,
            filename="rho_vs_metrics.png",
            dir_path="./plots")

Source from the content-addressed store, hash-verified

466
467
468def plot_sr_plus(results,
469 filename="rho_vs_metrics.png",
470 dir_path="./plots"):
471 """
472 绘制增强的结果图,包含多个指标:
473 1. 准确率(训练 & 测试)
474 2. 精确率 & F1 分数
475 3. 平均 ODE 积分时间
476 4. 分类器拟合 & 预测时间
477 """
478 if not results:
479 print("No results to plot.")
480 return
481
482 # 确保输出目录存在
483 os.makedirs(dir_path, exist_ok=True)
484
485 # 解包数据
486 srs, train_accs, test_accs, precisions, recalls, f1_scores, avg_ode_times, fit_times, pred_times = zip(*results)
487
488 # 创建 2x2 子图布局
489 fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(15, 12))
490
491 # 1. 准确率
492 ax1.plot(srs, train_accs, marker='o', label='Train Accuracy')
493 ax1.plot(srs, test_accs, marker='s', label='Test Accuracy')
494 ax1.set_xlabel('Spectral Radius')
495 ax1.set_ylabel('Accuracy')
496 ax1.set_title('Accuracy vs Spectral Radius')
497 ax1.grid(True)
498 ax1.legend()
499
500 # 2. 精确率 & F1 分数
501 ax2.plot(srs, precisions, marker='^', label='Precision')
502 ax2.plot(srs, recalls, marker='s', label='Recall')
503 ax2.plot(srs, f1_scores, marker='d', label='F1 Score')
504 ax2.set_xlabel('Spectral Radius')
505 ax2.set_ylabel('Score')
506 ax2.set_title('Precision, Recall & F1 Score vs Spectral Radius')
507 ax2.grid(True)
508 ax2.legend()
509
510 # 3. 平均 ODE 积分时间
511 ax3.plot(srs, avg_ode_times, marker='o', label='Avg ODE Time')
512 ax3.set_xlabel('Spectral Radius')
513 ax3.set_ylabel('Time (s)')
514 ax3.set_title('Average ODE Integration Time vs Spectral Radius')
515 ax3.grid(True)
516 ax3.legend()
517
518 # 4. 分类器时间
519 ax4.plot(srs, fit_times, marker='s', label='Fit Time')
520 ax4.plot(srs, pred_times, marker='^', label='Prediction Time')
521 ax4.set_xlabel('Spectral Radius')
522 ax4.set_ylabel('Time (s)')
523 ax4.set_title('Classifier Time vs Spectral Radius')
524 ax4.grid(True)
525 ax4.legend()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected