Model interface over frames and a model catalog
This commit is contained in:
@@ -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)
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user