Add event-free survival evaluation

This commit is contained in:
2026-06-27 11:48:47 +08:00
parent df6b45b95a
commit 3cd1109249
6 changed files with 2568 additions and 47 deletions

View File

@@ -395,40 +395,7 @@ def _metadata_count_map(dataset: HealthDataset, labels_meta: Optional[pd.DataFra
def _get_death_token_ids(dataset: HealthDataset, labels_meta: Optional[pd.DataFrame]) -> List[int]:
ids: List[int] = []
if labels_meta is not None and not labels_meta.empty:
meta = labels_meta.copy()
if "ICD-10 Chapter (short)" in meta.columns:
death_rows = meta[meta["ICD-10 Chapter (short)"].astype(
str) == "Death"]
code_col = _first_existing_column(
death_rows, ["Name", "code", "ICD10", "icd10", "label", "token", "disease_code"])
if code_col is not None:
for raw in death_rows[code_col].astype(str).tolist():
code = raw.split()[0].strip()
if code in dataset.label_code_to_id:
ids.append(int(dataset.label_code_to_id[code]))
elif "index" in death_rows.columns:
idx = pd.to_numeric(death_rows["index"], errors="coerce")
has_no_event = (
NO_EVENT_IDX in dataset.label_id_to_code
and dataset.label_id_to_code.get(NO_EVENT_IDX) == "<NO_EVENT>"
)
if has_no_event:
idx = idx.where(idx < NO_EVENT_IDX, idx + 1)
ids.extend(int(x) for x in idx.dropna().astype(int).tolist())
exact_codes = {"death", "<death>", "dth", "deceased", "mortality"}
for token, code in dataset.label_id_to_code.items():
token = int(token)
if token in SPECIAL_TOKENS:
continue
text = str(code).strip().lower()
if text in exact_codes or ("death" in text) or ("mortality" in text):
ids.append(token)
return sorted(set(int(x) for x in ids if int(x) not in SPECIAL_TOKENS))
return [int(dataset.vocab_size) - 1]
def _build_first_occurrence_maps(