Base classes and utility functions

Base classes

Base Bayes model and A/B testing classes.

class cprior.cdist.base.BayesABTest(modelA, modelB, simulations=None, random_state=None)

Bases: object

Bayes A/B test abstract class.

Parameters:
  • modelA (object) – The Bayes model for variant A.
  • modelB (object) – The Bayes model for variant B.
  • simulations (int or None (default=1000000)) – Number of Monte Carlo simulations.
  • random_state (int or None (default=None)) – The seed used by the random number generator.
class cprior.cdist.base.BayesModel

Bases: object

Bayes model class.

cdf(x)

Cumulative distribution function of the posterior distribution.

Parameters:x (array-like) – Quantiles.
Returns:cdf – Cumulative distribution function evaluated at x.
Return type:numpy.ndarray
credible_interval()

Credible interval of the posterior distribution.

Parameters:interval_length (float (default=0.9)) – Compute interval_length% credible interval. This is a value in [0, 1].
Returns:interval – Lower and upper credible interval limits.
Return type:tuple
mean()

Mean of the posterior distribution.

pdf(x)

Probability density function of the posterior distribution.

Parameters:x (array-like) – Quantiles.
Returns:pdf – Probability density function evaluated at x.
Return type:numpy.ndarray
ppf(q)

Percent point function (quantile) of the posterior distribution.

Parameters:x (array-like) – Lower tail probability.
Returns:ppf – Quantile corresponding to the lower tail probability q.
Return type:numpy.ndarray
rvs(size=1, random_state=None)

Random variates of the posterior distribution.

Parameters:
  • size (int (default=1)) – Number of random variates.
  • random_state (int or None (default=None)) – The seed used by the random number generator.
Returns:

rvs – Random variates of given size.

Return type:

numpy.ndarray or scalar

std()

Standard deviation of the posterior distribution.

update()

Update posterior parameters.

var()

Variance of the posterior distribution.

Utility functions

cprior.cdist.utils.check_ab_method(method, method_options, variant, lift=0)

Check parameters of A/B method.

Parameters:
  • method (str) – The default computational method.
  • method_options (list or tuple) – The list of supported computational methods.
  • variant (str) – The chosen variant. Options are “A”, “B”, “all”
  • lift (float (default=0.0)) – The amount of uplift.
cprior.cdist.utils.check_models(refclass, *models)

Check that models for A/B and multivariate testing belong to the correct class.

Parameters:
  • refclass (object) – Reference class.
  • models (objects) – Model instances to be checked.