CaCu training and scoring jobs on gold, MLflow versions with their reports
This commit is contained in:
+46
-2
@@ -1,9 +1,13 @@
|
||||
"""Dagster code location: every heavy step of the platform is a job defined here."""
|
||||
|
||||
from datetime import date
|
||||
|
||||
import dagster as dg
|
||||
|
||||
from models import graph
|
||||
from persistance import config_log
|
||||
from models.cacu import jobs as cacu
|
||||
from models.cacu.specs import MODELS as CACU_MODELS
|
||||
from persistance import config_log, silver
|
||||
|
||||
WRITES = {"writes": "platform"} # dagster.yaml lets one run with this tag at a time (SQLite)
|
||||
|
||||
@@ -27,4 +31,44 @@ def ingest():
|
||||
run_pipeline()
|
||||
|
||||
|
||||
defs = dg.Definitions(jobs=[ingest])
|
||||
class Training(dg.Config):
|
||||
models: list[str] = list(CACU_MODELS)
|
||||
as_of: str | None = None # the date the data are taken up to (default: today)
|
||||
|
||||
|
||||
@dg.op
|
||||
def train_models(context: dg.OpExecutionContext, config: Training) -> dict:
|
||||
"""A new registered version of each model (MLflow), with its reports."""
|
||||
as_of = date.fromisoformat(config.as_of) if config.as_of else None
|
||||
found = {}
|
||||
for name in config.models:
|
||||
found[name] = cacu.train(name, as_of)
|
||||
context.log.info(f"{name}: version {found[name]}")
|
||||
return found
|
||||
|
||||
|
||||
@dg.job
|
||||
def train_cacu():
|
||||
train_models()
|
||||
|
||||
|
||||
class Scoring(dg.Config):
|
||||
models: list[str] = list(CACU_MODELS)
|
||||
|
||||
|
||||
@dg.op
|
||||
def score_models(context: dg.OpExecutionContext, config: Scoring) -> dict:
|
||||
"""Each model's champion scores its cohort; then gold's risk tables are rebuilt."""
|
||||
found = {name: cacu.score(name) for name in config.models}
|
||||
for name, version in found.items():
|
||||
context.log.info(f"{name}: " + (f"version {version}" if version else "no champion"))
|
||||
silver.build(["cacu_risk+"])
|
||||
return found
|
||||
|
||||
|
||||
@dg.job(tags=WRITES)
|
||||
def score_cacu():
|
||||
score_models()
|
||||
|
||||
|
||||
defs = dg.Definitions(jobs=[ingest, train_cacu, score_cacu])
|
||||
|
||||
Reference in New Issue
Block a user