Every model trains on the site: EEG age curves on the children with TEA ruled out, recurrence on the site's patients (St. Gallen subtype), and the EEG–ADOS-2 association
This commit is contained in:
@@ -60,26 +60,41 @@ class Recurrence:
|
||||
|
||||
|
||||
def train(raws: dict[str, pd.DataFrame], bootstrap: bool = True) -> tuple[Recurrence, dict, dict]:
|
||||
"""Both cohorts' models, validation, calculator and risk factors, from their datasets'
|
||||
rows.
|
||||
"""Both reference cohorts' models, validation, calculator and risk factors, from their
|
||||
datasets' rows; the saved model is METABRIC's.
|
||||
Without `bootstrap`, the AUC bootstrap is skipped (its metrics, and the risk factors'
|
||||
stability criterion, are then missing)."""
|
||||
found = {s: cohorts.prepare(s, raws[s]) for s in SOURCES}
|
||||
return fit(found, SAVED, "metabric+scanb", bootstrap)
|
||||
|
||||
|
||||
def train_site(rows: pd.DataFrame, bootstrap: bool = True) -> tuple[Recurrence, dict, dict]:
|
||||
"""The same, on the site's own cohort (models.cama.recurrence.site)."""
|
||||
from models.cama.recurrence import site
|
||||
|
||||
return fit({"site": site.prepare(rows)}, "site", "site", bootstrap)
|
||||
|
||||
|
||||
def fit(found: dict, saved: str, label: str,
|
||||
bootstrap: bool = True) -> tuple[Recurrence, dict, dict]: # fmt: skip
|
||||
"""The models of each prepared cohort, their validation, calculator and risk factors;
|
||||
the `saved` cohort's is the model kept."""
|
||||
sources = list(found)
|
||||
n_bootstrap = modeling.N_BOOTSTRAP if bootstrap else {}
|
||||
try:
|
||||
fits = modeling.fit(found, n_bootstrap)
|
||||
drawn = {s: calculator.calculator(fits[s]) for s in SOURCES}
|
||||
drawn = {s: calculator.calculator(fits[s]) for s in sources}
|
||||
finally:
|
||||
joblib.externals.loky.get_reusable_executor().shutdown(wait=True)
|
||||
table = pd.concat([factors.risk_factors(fits[s]) for s in SOURCES], ignore_index=True)
|
||||
summary = [row for s in SOURCES for row in factors.scenario_summary(fits[s], table)]
|
||||
auc = [row for s in SOURCES for row in reports.auc_rows(fits[s])]
|
||||
points = [row for s in SOURCES for row in drawn[s][1]]
|
||||
saved = fits[SAVED]
|
||||
model = Recurrence(SAVED, HORIZONS, saved.cohort.covariates, modeling.tables(saved))
|
||||
table = pd.concat([factors.risk_factors(fits[s]) for s in sources], ignore_index=True)
|
||||
summary = [row for s in sources for row in factors.scenario_summary(fits[s], table)]
|
||||
auc = [row for s in sources for row in reports.auc_rows(fits[s])]
|
||||
points = [row for s in sources for row in drawn[s][1]]
|
||||
kept = fits[saved]
|
||||
model = Recurrence(saved, HORIZONS, kept.cohort.covariates, modeling.tables(kept))
|
||||
technical = {
|
||||
"model": "recurrence",
|
||||
"cohort": "metabric+scanb",
|
||||
"cohort": label,
|
||||
"method": "stepwise logistic regression + Bayesian network (BDeu), averaged",
|
||||
"rutinas": reports.routines(found, n_bootstrap),
|
||||
"recurrencia_desarrollo": reports.development(auc, table, points, summary),
|
||||
@@ -87,7 +102,7 @@ def train(raws: dict[str, pd.DataFrame], bootstrap: bool = True) -> tuple[Recurr
|
||||
interpretability = {
|
||||
"model": "recurrence",
|
||||
"kind": "scenarios",
|
||||
"recurrencia": reports.figures([r for s in SOURCES for r in drawn[s][0]]),
|
||||
"recurrencia": reports.figures([r for s in sources for r in drawn[s][0]]),
|
||||
}
|
||||
reports_ = {"technical_validation": technical, "interpretability": interpretability}
|
||||
return model, reports.metrics(auc), reports_
|
||||
|
||||
Reference in New Issue
Block a user