
Production scoring bundle with a train/serve skew guard
Source:R/scoring.R
omop_scoring_pipeline.RdTies a fitted imputer, scaler and model to the ORDERED feature schema they were trained on, and refuses to score a
data frame whose columns do not match that schema. It is model-agnostic: the stages are plain functions (or lists
of functions), so any R modelling package works. Mirror of omop_etl.scoring.OMOPScoringPipeline in Python.
Arguments
- predict_fn
function(x)taking the transformed numeric matrix and returning the positive-class probability (one value per row).- feature_names
Ordered feature columns the stages were fitted on.
- impute_fn, scale_fn
Optional
function(x)applied (imputer first, then scaler) to the numeric matrix. They must be closures over the values learned at fit time.- metadata
Free-form list stored with the bundle (cohort definition, git sha, training dates, ...).
- strict
If
TRUE(default) columns not in the schema raise an error instead of being dropped.- allow_missing_values
If
FALSE(default)NAin the input raises unlessimpute_fnis given.- ranges
Optional named list
feature -> c(min, max)seen at fit time (used byscoring_pipeline_out_of_range()).
Details
Pair it with the leak-free feature extractors (extract_elixhauser_comorbidities(exclude_index_diagnoses = TRUE),
extract_prior_utilization()) so the features available at training time are the ones available at the bedside.
Bundles are saved with base::saveRDS(); only load files you created or trust.