fix: evaluate AUC on fixed test EIDs

This commit is contained in:
2026-08-03 13:56:06 +08:00
parent 271a678e73
commit e040707d07
4 changed files with 280 additions and 26 deletions

View File

@@ -135,6 +135,39 @@ def split_indices(
)
def select_indices_by_eid_file(
dataset: Any,
eid_file: str | Path,
) -> Tuple[np.ndarray, Path]:
"""Return dataset indices whose patient EIDs occur in ``eid_file``."""
from train_util import load_eid_file
path = Path(eid_file)
if not path.is_absolute():
direct = Path.cwd() / path
path = direct if direct.is_file() else Path(__file__).resolve().parent / path
if not path.is_file():
raise FileNotFoundError(f"EID split file not found: {path}")
samples = getattr(dataset, "samples", None)
if samples is None:
raise TypeError("EID-based evaluation requires dataset.samples")
selected_eids = load_eid_file(path)
indices = np.asarray(
[
index
for index, sample in enumerate(samples)
if int(sample["eid"]) in selected_eids
],
dtype=np.int64,
)
if indices.size == 0:
raise ValueError(
f"No dataset patients matched the EID split file: {path}"
)
return indices, path.resolve()
def build_model_from_dataset(
args: argparse.Namespace,
cfg: Dict[str, Any],