diff --git a/lnp_ml/modeling/nested_cv_optuna.py b/lnp_ml/modeling/nested_cv_optuna.py index b235d10..5fd94c3 100644 --- a/lnp_ml/modeling/nested_cv_optuna.py +++ b/lnp_ml/modeling/nested_cv_optuna.py @@ -632,6 +632,21 @@ def _run_single_outer_fold( fold_dir.mkdir(parents=True, exist_ok=True) full_dataset = LNPDataset(df) + # === 断点续跑:已完成的 fold 直接跳过(读回磁盘结果)=== + _tm = fold_dir / "test_metrics.json" + _bp = fold_dir / "best_params.json" + _em = fold_dir / "epoch_mean.json" + if precomputed_best_params is None and _tm.exists() and _bp.exists() and _em.exists(): + logger.success(f"[SKIP] Outer fold {outer_fold} already done, loading cached results.") + with open(_tm) as _f: _tmd = json.load(_f) + with open(_bp) as _f: _bpd = json.load(_f) + with open(_em) as _f: _emd = json.load(_f) + return { + "fold": outer_fold, + "best_params": _bpd, + "epoch_mean": int(_emd.get("epoch_mean", _emd) if isinstance(_emd, dict) else _emd), + "test_metrics": _tmd, + } logger.info(f"\n{'='*60}") logger.info(f"OUTER FOLD {outer_fold}")