clvkit.BGNBD#

class BGNBD[source]#

Bases: object

The BG/NBD transaction-flow model.

Three verbs, no aliases:

model = BGNBD().fit(cb)
model.predict(t=12).to_pandas()      # expected purchases in the next 12 time units
model.probability_alive().to_pandas()

Fitting is maximum likelihood — no sampler, no priors, no convergence diagnostics to read.

fit(cb)[source]#

Estimate (r, alpha, a, b) by maximum likelihood on cb.

The optimiser works on log parameters so the search is unconstrained while the parameters stay strictly positive, which is what the gamma and beta priors of section 3 require.

Parameters:

cb (CustomerBase)

Return type:

BGNBD

predict(t, cb=None)[source]#

Expected purchases in the next t time units, per customer.

t is in the fitted base’s own time_unit. Pass cb to score a different customer base than the one fitted on — it must carry the same time_unit, or the answer would silently be in the wrong units.

Parameters:
Return type:

Prediction

probability_alive(cb=None)[source]#

P(each customer is still active) at the base’s observation period end.

Parameters:

cb (CustomerBase | None)

Return type:

Prediction