ModelBuilder#
- class pymc_extras.model_builder.ModelBuilder(model_config: dict | None = None, sampler_config: dict | None = None)[source]#
ModelBuilder can be used to provide an easy-to-use API (similar to scikit-learn) for models and help with deployment.
- __init__(model_config: dict | None = None, sampler_config: dict | None = None)[source]#
Initializes model configuration and sampler configuration for the model
- Parameters:
data (Dictionary, optional) – It is the data we need to train the model on.
model_config (Dictionary, optional) – dictionary of parameters that initialise model configuration. Class-default defined by the user default_model_config method.
sampler_config (Dictionary, optional) – dictionary of parameters that initialise sampler configuration. Class-default defined by the user default_sampler_config method.
Examples
>>> class MyModel(ModelBuilder): >>> ... >>> model = MyModel(model_config, sampler_config)
Methods
__init__
([model_config, sampler_config])Initializes model configuration and sampler configuration for the model
build_model
(X, y, **kwargs)Creates an instance of pm.Model based on provided data and model_config, and attaches it to self.
fit
(X[, y, progressbar, predictor_names, ...])Fit a model using the data passed as a parameter.
get_default_model_config
()Returns a class default config dict for model builder if no model_config is provided on class initialization Useful for understanding structure of required model_config to allow its customization by users
get_default_sampler_config
(self)Returns a class default sampler dict for model builder if no sampler_config is provided on class initialization Useful for understanding structure of required sampler_config to allow its customization by users
get_params
([deep])Get all the model parameters needed to instantiate a copy of the model, not including training data.
load
(fname)Creates a ModelBuilder instance from a file, Loads inference data for the model.
predict
(X_pred[, extend_idata])Uses model to predict on unseen data and return point prediction of all the samples.
predict_posterior
(X_pred[, extend_idata, ...])Generate posterior predictive samples on unseen data.
predict_proba
(X_pred[, extend_idata, combined])Alias for predict_posterior, for consistency with scikit-learn probabilistic estimators.
sample_model
(**kwargs)Sample from the PyMC model.
sample_posterior_predictive
(X_pred, ...)Sample from the model's posterior predictive distribution.
sample_prior_predictive
(X_pred[, y_pred, ...])Sample from the model's prior predictive distribution.
save
(fname)Save the model's inference data to a file.
set_idata_attrs
([idata])Set attributes on an InferenceData object.
set_params
(**params)Set all the model parameters needed to instantiate the model, not including training data.
Attributes
id
Generate a unique hash value for the model.
output_var
Returns the name of the output variable of the model.
version