CaCu survival: each risk comes with its combination's bootstrap interval
The covariates are categorical, so every member of a combination gets the same mortality. Training keeps, per combination of its members, the percentiles of the mortality of `risk_interval_replicas` refits on bootstrap resamples (`risk_interval_level`, 0.95), and estimating writes it as each risk's interval. A combination training never saw has none.
This commit is contained in:
@@ -37,7 +37,7 @@ CONFIG = SCENARIO.config
|
||||
WINDOW = {"recruitment_start": "2018-01-01", "recruitment_end": "2027-01-01", "cutoff": CUTOFF.isoformat()}
|
||||
LINEAGE = {"url": "cacu/cohorte_total", "datos_as_of": CUTOFF.isoformat(), "parametros": json.dumps(WINDOW)}
|
||||
N = 240
|
||||
QUICK = {**CONFIG, "survival": {**CONFIG["survival"], "n_boot": 20, "ks_max_seconds": 5}}
|
||||
QUICK = {**CONFIG, "survival": {**CONFIG["survival"], "n_boot": 20, "ks_max_seconds": 5}, "risk_interval_replicas": 20}
|
||||
|
||||
|
||||
def _row(pac_id, when, tipo, valor=None, source="t", source_id=None, first=None):
|
||||
@@ -130,7 +130,7 @@ def test_the_graph_takes_exactly_its_config_and_the_cohort():
|
||||
assert required == {"source_cohort", "cohort_lineage", "age_cuts", "cytology", "etiquetas", "horizons_years",
|
||||
"index", "survival", "train_fraction"}
|
||||
# `index` is required: the registered model re-indexes a build with it.
|
||||
assert optional == {"calibration_bins", "report_panels"}
|
||||
assert optional == {"calibration_bins", "report_panels", "risk_interval_level", "risk_interval_replicas"}
|
||||
|
||||
|
||||
def _primer_carcinoma(frame: pd.DataFrame) -> pd.Series:
|
||||
@@ -219,8 +219,9 @@ def test_the_dataflow_reaches_its_metrics_routines_and_population_record_without
|
||||
def test_training_registers_a_version_and_estimating_dates_each_risk_by_the_models_index(cohort_file, mlflow_tracking,
|
||||
tmp_path):
|
||||
"""Pins down: training on a build's file registers a version with its population record; estimating with it writes
|
||||
one row per scored member and horizon, dated by the model's index (the carcinoma biopsy), with the members the
|
||||
scenario leaves out absent. Fails if the version cannot score a build or the estimate keeps the cohort's index."""
|
||||
one row per scored member and horizon, dated by the model's index (the carcinoma biopsy), with its combination's
|
||||
bootstrap interval holding it, and with the members the scenario leaves out absent. Fails if the version cannot
|
||||
score a build, the estimate keeps the cohort's index, or the risks lose their interval."""
|
||||
version = train(dataclasses.replace(SCENARIO, config=QUICK), CohortFile(cohort_file))
|
||||
output = tmp_path / "estimate.parquet"
|
||||
|
||||
@@ -234,6 +235,8 @@ def test_training_registers_a_version_and_estimating_dates_each_risk_by_the_mode
|
||||
inicio = date.fromisoformat(WINDOW["recruitment_start"])
|
||||
antes = set(_primer_carcinoma(read_cohort(cohort_file))[lambda d: d < inicio].index)
|
||||
assert set(risks["horizonte_anios"]) == {1.0, 3.0, 5.0}
|
||||
assert risks[["ic_bajo", "ic_alto"]].notna().all().all()
|
||||
assert ((risks["ic_bajo"] <= risks["probabilidad"]) & (risks["probabilidad"] <= risks["ic_alto"])).mean() > 0.9
|
||||
assert set(risks["pac_id"]) == (set(range(1, N + 1)) | {241}) - antes
|
||||
frame = read_cohort(cohort_file)
|
||||
diagnosis = frame[(frame["tipo"] == "biopsia") & (frame["valor_codigo"] == "CARCINOMA") & (frame["pac_id"] == 1)]
|
||||
|
||||
Reference in New Issue
Block a user