General problem statement – I’m trying to predict terminal conversion rates for cohorts that take a while to mature based on their data “so far”. To do so, I’m using a Beta distribution to characterize the typical conversion rates over an observed bernoulli distribution of the conversion rates so far for the cohort.
Here is what a typical conversion rate distribution looks like for a given cohort and step in my process:
Naturally, those peaks at 0 and 1 cause issues when I use a beta alone. I attempted to follow an existing thread here, and arrived at the following code where historic_a and _b are found using scipy to fit a beta to the non 0 or 1 historical conversion rates:
test_obs_data = sp.stats.bernoulli.rvs(0.33, 200) epsilon = 1e-3 historic_a = 9 historic_b = 75 with pm.Model() as model: mixture_beta = pm.Beta.dist(historic_a, historic_b) u_0 = pm.Uniform.dist(0, epsilon) u_1 = pm.Uniform.dist(1-epsilon, 1) p = pm.Beta('p', 1, 1, shape=2) dists = [u_0, u_1, mixture_beta] weights = [p, (1-p)*p, (1-p)*(1-p)] mixture = pm.Mixture('mixture', w=weights, comp_dists=dists) obs = pm.Bernoulli('obs', mixture, observed=test_obs_data) trace = pm.sample(2000)
The above code results in an error:
AttributeError: Can't pickle local object 'Mixture._comp_dist_random_wrapper.<locals>.wrapped_random'
What am I doing wrong?