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:
statslist of str, optional

List of sample statistics to log from the Draw

parameterslist of str, optional

List of parameters to log from the Draw

exclude_tuningbool, optional

Whether to exclude tuning steps from logging. Defaults to True.

take_everyint, optional

Specifies the interval at which to log values. Defaults to 100.

Returns:
callbackCallable

The callback function to log sample stats and parameter values to MLflow during sampling

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 mu and sigma_log__ every 100th draw:

import mlflow

from pymc_marketing.mlflow import create_log_callback

callback = create_log_callback(
    parameters=["mu", "sigma_log__"],
    take_every=100,
)

mlflow.set_experiment("Live Tracking Parameters")

with mlflow.start_run():
    idata = pm.sample(model=model, callback=callback)