clvkit.GammaGamma#

class GammaGamma[source]#

Bases: object

Spend per transaction, estimated by maximum likelihood.

Individual transaction values are gamma(p, ν); ν itself is gamma(q, γ) across customers (note §2), which makes a customer’s unobserved mean transaction value ζ inverse-gamma with shape q and scale pγ.

>>> gg = GammaGamma().fit(cb)
>>> gg.predict().to_pandas()
property params_: Series | None#

The fitted (p, q, γ), or None before fitting.

A view over p, q and gamma rather than a fourth copy of them — the three named floats stay the source of truth, because the formulae in this module read them individually. It exists so that a caller holding a transaction model and a monetary model can read both the same way; BGNBD has carried params_ since it was written, and anything wanting to render or compare the two had to special-case this class for want of it.

fit(cb)[source]#

Estimate (p, q, γ) by maximising the sample log-likelihood (6).

Only customers with at least one repeat transaction carry information about spend; one-time buyers have no observed average and contribute nothing to the likelihood (note §3, “Parameter Estimation”).

Parameters:

cb (CustomerBase)

Return type:

GammaGamma

predict(cb=None)[source]#

Expected spend per transaction, E(Z | p, q, γ; z̄, x), per customer.

There is no horizon argument: assumption 2 makes a customer’s average transaction value constant over time, so this is the same number whether you look one week or one year ahead.

Parameters:

cb (CustomerBase | None)

Return type:

Prediction

population_mean()[source]#

E(Z | p, q, γ) = pγ/(q − 1) — mean spend across the population (3).

Return type:

float