How to use the lifetimes.BetaGeoFitter function in Lifetimes

To help you get started, we’ve selected a few Lifetimes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CamDavidsonPilon / lifetimes / tests / View on Github external
def fitted_bg(example_summary_data):
    bg = BetaGeoFitter()['frequency'], example_summary_data['recency'], example_summary_data['T'], iterative_fitting=2, tol=1e-6)
    return bg
github CamDavidsonPilon / lifetimes / tests / View on Github external
def bgf_transactions(cdnow_transactions):
    transactions_summary = utils.summary_data_from_transaction_data(
        cdnow_transactions, 'id_sample', 'date', datetime_format='%Y%m%d',
        observation_period_end='19970930', freq='W')

    bgf = BetaGeoFitter(penalizer_coef=0.01)['frequency'],
            transactions_summary['recency'], transactions_summary['T'])
    return bgf
github CamDavidsonPilon / lifetimes / tests / View on Github external
customer_id_col = 'id_sample'
    t = 14
    datetime_format = '%Y%m%d'
    freq = 'D'
    observation_period_end = '19970930'
    freq_multiplier = 1

    transactions_summary = utils.summary_data_from_transaction_data(
        cdnow_transactions, customer_id_col, datetime_col,
        datetime_format=datetime_format, freq=freq,

    transactions_summary = transactions_summary.reset_index()

    model = BetaGeoFitter()['frequency'],

    df_cum = utils.expected_cumulative_transactions(
        model, cdnow_transactions, datetime_col, customer_id_col, t,
        datetime_format, freq, set_index_date=True,

    dates = ['1997-01-11', '1997-01-12', '1997-01-13', '1997-01-14']
    actual_trans = [11, 12, 15, 19]
    expected_trans = [10.67, 12.67, 14.87, 17.24]

    date_index = df_cum.iloc[-4:].index.to_timestamp().astype(str)
    actual = df_cum['actual'].iloc[-4:].values
    predicted = df_cum['predicted'].iloc[-4:].values.round(2)
github CamDavidsonPilon / lifetimes / tests / View on Github external
def bgf(cd_data):
    bgf_model = BetaGeoFitter()['frequency'], cd_data['recency'], cd_data['T'], iterative_fitting=1)
    return bgf_model
github CamDavidsonPilon / lifetimes / lifetimes / fitters / View on Github external
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import division
import warnings

import autograd.numpy as np
from autograd.numpy import log, logaddexp
from autograd.scipy.special import gammaln, beta, gamma
from scipy.special import hyp2f1

from lifetimes import BetaGeoFitter
from lifetimes.generate_data import modified_beta_geometric_nbd_model

class ModifiedBetaGeoFitter(BetaGeoFitter):
    Also known as the MBG/NBD model.

    Based on [5]_, [6]_, this model has the following assumptions:
    1) Each individual, ``i``, has a hidden ``lambda_i`` and ``p_i`` parameter
    2) These come from a population wide Gamma and a Beta distribution
    3) Individuals purchases follow a Poisson process with rate :math:`\lambda_i*t` .
    4) At the beginning of their lifetime and after each purchase, an
       individual has a p_i probability of dieing (never buying again).

    .. [5] Batislam, E.P., M. Denizel, A. Filiztekin (2007),
       "Empirical validation and comparison of models for customer base