Estimates: each risk's interval when the model gives one; a member it can't place has no rows

A run with `risk_interval_level` has a model that gives, after the risk at each horizon, its interval's lower and
upper ends; the estimate keeps them as `ic_bajo` and `ic_alto`, the contract checks that they hold the risk, and the
batch stores them. `scored_frame` is the one place that reads the run and calls the model, for the command and the
WebApi's cycle. A member whose risk is NaN (a combination the model never saw) is left out instead of stopping the
whole batch.
This commit is contained in:
2026-11-22 07:38:17 -06:00
parent 271c799d0a
commit 78a4748592
5 changed files with 95 additions and 22 deletions
+6 -1
View File
@@ -48,7 +48,12 @@ ESTIMATE_FRAME = pandera.DataFrameSchema(
{"pac_id": pandera.Column(int, pandera.Check.gt(0)),
"fecha_indice": pandera.Column(nullable=False),
"horizonte_anios": pandera.Column(float, pandera.Check.ge(0)),
"probabilidad": pandera.Column(float, pandera.Check.in_range(0, 1))},
"probabilidad": pandera.Column(float, pandera.Check.in_range(0, 1)),
# the risk's interval, from a model that gives one (NaN where it can't)
"ic_bajo": pandera.Column(float, pandera.Check.in_range(0, 1), nullable=True, required=False),
"ic_alto": pandera.Column(float, pandera.Check.in_range(0, 1), nullable=True, required=False)},
checks=pandera.Check(lambda f: ~(f["ic_bajo"] > f["probabilidad"]) & ~(f["ic_alto"] < f["probabilidad"])
if "ic_bajo" in f else pd.Series(True, index=f.index), error="ic_bajo <= probabilidad <= ic_alto"),
strict=True, ordered=True, unique=["pac_id", "horizonte_anios"], name="estimate")
POPULATION, INDEX, EXCLUSION, VARIABLES = "population", "index", "exclusion", "variables"