CLVModel.fit#
- CLVModel.fit(data=None, *, method='mcmc', progressbar=None, random_seed=None, sample_kwargs=None, map_kwargs=None, **kwargs)[source]#
Infer the model posterior.
Sets attrs on the inference data of the model.
- Parameters:
- data
Any, optional Input data for model fitting. If
None, the data already held by the instance is used. Models that do not override_prepare_fitraise aNotImplementedErrorwhen data is passed here.- method
str Method used to fit the model. Options are:
"mcmc": Samples from the posterior viapymc.sample(default)"map": Finds maximum a posteriori viapymc.find_MAP"demz": Samples from the posterior viapymc.sampleusing DEMetropolisZ"advi": Samples viapymc.fit(method="advi")andApproximation.sample"fullrank_advi": As"advi", with a full-rank approximation
Note this selects the sampler, not
pymc.find_MAP’smethodargument (the scipy optimizer). Usemap_kwargsto reach the latter.- progressbarbool, optional
Specifies whether the fit progress bar should be displayed. Defaults to True.
- random_seed
RandomState, optional Provides the sampler with an initial random seed for reproducible samples.
- sample_kwargs
dict, optional Only used by the variational methods; forwarded to
Approximation.sample(e.g.{"draws": 1_000}).- map_kwargs
dict, optional Only used by
method="map"; forwarded topymc.find_MAPafter the other keyword arguments have been filtered. Use it for namesfitwould otherwise shadow, e.g.{"method": "Powell"}to pick the optimizer.- **kwargs
Any Custom sampler settings, passed to the underlying PyMC routine.
- data
- Returns:
xr.DataTreeInference data of the fitted model.
Examples
model = MyModel() idata = model.fit(data) idata = model.fit(data, method="map")