Baseline IO

class neer_match_utilities.baseline_io.ModelBaseline[source]

Save/load utilities for non-DL baseline models: - LogitMatchingModel - ProbitMatchingModel - GradientBoostingModel

static load(model_directory)[source]

Load a baseline model.

Reads both layouts: models saved with the training data embedded in the statsmodels result (the original behavior), and models saved without it. In the latter case the regression table is restored from meta.pkl so that summary() and coefficients() keep working.

static save(model, target_directory, name, similarity_map=None, remove_data=True)[source]
Parameters:
  • similarity_map (SimilarityMap | dict | None) – Pass either a SimilarityMap instance OR the underlying dict (instructions). This is stored so that ModelBaseline.load(…) can return a model with loaded_model.similarity_map just like the DL models.

  • remove_data (bool) –

    Only relevant for the statsmodels baselines (Logit/Probit). A statsmodels Results object keeps a reference to its Model, and hence to the full endog/exog arrays. Since the design matrix here is the entire left x right cross join, pickling it verbatim costs roughly 1.9 KB per training pair – tens of gigabytes on realistic data – in order to persist a coefficient vector of a few hundred bytes.

    When True (default), the regression table is rendered and stored in meta.pkl first, and the result is then pickled without its data. The artifact becomes a few hundred KB regardless of dataset size; predict_proba, evaluate, suggest and summary all keep working on the reloaded model. What is lost is the ability to recompute data-dependent quantities (residuals, influence measures) from the archive.

    Set to False to reproduce the old behavior and pickle the data along with the model.

Return type:

None

Notes

With remove_data=True statsmodels strips the arrays from the in-memory result as well, so the passed-in model loses its residuals and influence measures too. Its coefficients, predictions and summary are unaffected.