Mantener la paridad declarando que el VPH ausente ya no es negativo

This commit is contained in:
2026-12-03 19:27:21 -06:00
parent f99cca5176
commit 04c9b3124b
+16
View File
@@ -15,8 +15,10 @@ import pandas as pd
import pytest
from joblib import parallel_config
from core import cacu
from models import curves, survival
from models.cacu import reports
from models.cacu.features import days, prepared
from models.cacu.specs import MODELS
REFERENCE = Path(__file__).parents[2] / "tests" / "fixtures" / "reference" / "cacu"
@@ -58,11 +60,25 @@ def timelines(cohort: str) -> pd.DataFrame:
return found
def hpv_missing_as_the_current_platform_read_it(events: pd.DataFrame) -> pd.DataFrame:
"""Changed on purpose: the rewrite does not evaluate a patient without an HPV result at the
index; the current platform read it as negative. Standing in a result that is not positive
here keeps the rest of the computation compared."""
index = events.groupby("person_id", as_index=False).first()
near = days(prepared(events)).between(0, cacu.INDEX_SAMPLE_DAYS)
has = events[(events["type"] == "hpv") & near]
missing = index[~index["person_id"].isin(has["person_id"])]
assumed = missing.assign(date=missing["index_date"], type="hpv", value_code="assumed") # not positive, and not a negative visit
return pd.concat([events, assumed[events.columns]], ignore_index=True)
@pytest.mark.parametrize("name", ["cin2_pim", "cancer_pim", "cin2_pim_post_treatment",
"cin2_logistic"]) # fmt: skip
def test_predictions_match_the_current_models(name):
spec = MODELS[name]
events = timelines(COHORTS[spec.cohort])
if spec.method != "logistic regression":
events = hpv_missing_as_the_current_platform_read_it(events)
args = (REFERENCE_CUTOFF,) if spec.method == "logistic regression" else ()
model, metrics, _ = spec.train(events, *args)
reference = pd.read_parquet(REFERENCE / "ref" / f"{name}.parquet")