Model interface over frames and a model catalog

This commit is contained in:
2026-11-04 20:39:52 -06:00
parent 34de6e9348
commit 27e29804aa
7 changed files with 243 additions and 6 deletions
+20
View File
@@ -0,0 +1,20 @@
"""A test model: predicts the training rows' share of `y`. `y` is 1 if a member has any Bethesda result that isn't
`NORMAL`; its only predictor is the member's number of Bethesda results."""
import pandas as pd
def prepare(cohort: pd.DataFrame) -> pd.DataFrame:
results = cohort[cohort["tipo"] == "bethesda"]
abnormal = results["valor_codigo"].ne("NORMAL").groupby(results["pac_id"]).any()
prepared = results.groupby(["pac_id", "fecha_indice"], as_index=False).size().rename(columns={"size": "n_results"})
prepared["y"] = prepared["pac_id"].map(abnormal).astype(int)
return prepared
def fit(train: pd.DataFrame) -> float:
return float(train["y"].mean())
def predict(fit: float, test: pd.DataFrame) -> pd.Series:
return pd.Series(fit, index=test.index)
+9
View File
@@ -0,0 +1,9 @@
"""A module that isn't a model: it has no `predict`."""
def prepare(cohort):
return cohort
def fit(train):
return None