Evaluar regresiones de desarrollo con selección anidada
This commit is contained in:
+43
-1
@@ -90,6 +90,47 @@ def score():
|
||||
score_models()
|
||||
|
||||
|
||||
class CacuDevelopmentEvaluation(dg.Config):
|
||||
as_of: str
|
||||
max_fits: int = 100000
|
||||
|
||||
|
||||
@dg.op
|
||||
def evaluate_cacu_development(context: dg.OpExecutionContext, config: CacuDevelopmentEvaluation) -> str:
|
||||
"""Opt-in research evaluation only: no registered model, promotion or patient scores."""
|
||||
import mlflow
|
||||
import pandas as pd
|
||||
|
||||
from core import cacu
|
||||
from models.cacu import encoders, features
|
||||
from models.cacu.development_selection import evaluate
|
||||
from persistance import gold, registry
|
||||
|
||||
as_of = date.fromisoformat(config.as_of)
|
||||
cohort = "cacu_cohort_surveillance"
|
||||
events = gold.evidence_timelines("cacu_events", cohort, as_of)
|
||||
if events.empty:
|
||||
raise EmptyCohort(f"no eligible patients in {cohort}")
|
||||
encoded = encoders.encode(events, gold.cervical_forms(cohort))
|
||||
outcome = features.windowed_outcome(features.prepared(events), cacu.CIN2_PLUS, 1.0,
|
||||
pd.Timestamp(as_of))
|
||||
rows = encoded.merge(outcome, on="person_id", validate="one_to_one")
|
||||
rows = rows[rows["known"]].reset_index(drop=True)
|
||||
X = rows.drop(columns=["person_id", "index_date", "known", "y"])
|
||||
report = evaluate(X, rows["y"].to_numpy(), max_fits=config.max_fits)
|
||||
report.update(cohort=cohort, as_of=as_of.isoformat(), outcome="CIN2+ at one year")
|
||||
mlflow.set_experiment(registry.EXPERIMENT)
|
||||
with mlflow.start_run(run_name="cacu.cin2_firth_development") as run:
|
||||
mlflow.log_dict(report, "reports/development_evaluation.json")
|
||||
context.log.info("Development evaluation logged as %s", run.info.run_id)
|
||||
return run.info.run_id
|
||||
|
||||
|
||||
@dg.job
|
||||
def cacu_development_evaluation():
|
||||
evaluate_cacu_development()
|
||||
|
||||
|
||||
class Analysis(dg.Config):
|
||||
domain: str
|
||||
|
||||
@@ -144,4 +185,5 @@ nightly = (
|
||||
else []
|
||||
)
|
||||
|
||||
defs = dg.Definitions(jobs=[ingest, train, score, analyze, rebuild, backup], schedules=nightly)
|
||||
defs = dg.Definitions(jobs=[ingest, train, score, analyze, rebuild, backup,
|
||||
cacu_development_evaluation], schedules=nightly)
|
||||
|
||||
Reference in New Issue
Block a user