Skip to contents

Ties 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.

Usage

omop_scoring_pipeline(
  predict_fn,
  feature_names,
  impute_fn = NULL,
  scale_fn = NULL,
  metadata = list(),
  strict = TRUE,
  allow_missing_values = !is.null(impute_fn),
  ranges = list()
)

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) NA in the input raises unless impute_fn is given.

ranges

Optional named list feature -> c(min, max) seen at fit time (used by scoring_pipeline_out_of_range()).

Value

An object of class omop_scoring_pipeline.

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.