create_log_callback#
- pymc_marketing.mlflow.create_log_callback(stats=None, parameters=None, exclude_tuning=True, take_every=100)[source]#
Create callback function to log sample stats and parameter values to MLflow during sampling.
This callback only works for the “pymc” sampler.
- Parameters:
- stats
listofstr, optional List of sample statistics to log from the Draw
- parameters
listofstr, optional Names of variables to log from the draw PyMC has just recorded. A model-level name such as
sigmais logged on its constrained scale, a value variable name such assigma_log__on the sampler’s unconstrained scale. Deterministics can be logged too. Each value must be a scalar, sincemlflow.log_metriconly accepts scalars.- exclude_tuningbool, optional
Whether to exclude tuning steps from logging. Defaults to True.
- take_every
int, optional Specifies the interval at which to log values. Defaults to 100.
- stats
- Returns:
- callback
Callable The callback function to log sample stats and parameter values to MLflow during sampling
- callback
Examples
Create example model:
import pymc as pm with pm.Model() as model: mu = pm.Normal("mu") sigma = pm.HalfNormal("sigma") obs = pm.Normal("obs", mu=mu, sigma=sigma, observed=[1, 2, 3])
Log off divergences and logp every 100th draw:
import mlflow from pymc_marketing.mlflow import create_log_callback callback = create_log_callback( stats=["diverging", "model_logp"], take_every=100, ) mlflow.set_experiment("Live Tracking Stats") with mlflow.start_run(): idata = pm.sample(model=model, callback=callback)
Log the parameters
muandsigmaevery 100th draw. PyMC samplessigmaon the unconstrained scale assigma_log__; the callback logssigmaitself, read from the draw PyMC just recorded. Passsigma_log__to log the unconstrained value instead:import mlflow from pymc_marketing.mlflow import create_log_callback callback = create_log_callback( parameters=["mu", "sigma"], take_every=100, ) mlflow.set_experiment("Live Tracking Parameters") with mlflow.start_run(): idata = pm.sample(model=model, callback=callback)