How to use the lifetimes.fitters.BaseFitter 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 / lifetimes / fitters / beta_geo_fitter.py View on Github external
from __future__ import print_function
from __future__ import division
import warnings

import pandas as pd
import autograd.numpy as np
from autograd.scipy.special import gammaln, beta, gamma
from scipy.special import hyp2f1
from scipy.special import expit
from . import BaseFitter
from ..utils import _scale_time, _check_inputs
from ..generate_data import beta_geometric_nbd_model


class BetaGeoFitter(BaseFitter):
    """
    Also known as the BG/NBD model.

    Based on [2]_, 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
       respectively.
    3) Individuals purchases follow a Poisson process with rate lambda_i*t .
    4) After each purchase, an individual has a p_i probability of dieing
       (never buying again).

    Parameters
    ----------
    penalizer_coef: float
        The coefficient applied to an l2 norm on the parameters
github CamDavidsonPilon / lifetimes / lifetimes / fitters / beta_geo_beta_binom_fitter.py View on Github external
warnings.simplefilter(action="ignore", category=FutureWarning)

import numpy as np
import pandas as pd
from autograd.numpy import log, exp, logaddexp
from pandas import DataFrame
from autograd.scipy.special import gammaln, betaln, beta as betaf
from scipy.special import binom

from ..utils import _check_inputs
from . import BaseFitter
from ..generate_data import beta_geometric_beta_binom_model


class BetaGeoBetaBinomFitter(BaseFitter):
    """
    Also known as the Beta-Geometric/Beta-Binomial Model [1]_.

    Future purchases opportunities are treated as discrete points in time.
    In the literature, the model provides a better fit than the Pareto/NBD
    model for a nonprofit organization with regular giving patterns.

    The model is estimated with a recency-frequency matrix with n transaction
    opportunities.

    Parameters
    ----------
    penalizer_coef: float
        The coefficient applied to an l2 norm on the parameters

    Attributes
github CamDavidsonPilon / lifetimes / lifetimes / fitters / gamma_gamma_fitter.py View on Github external
from __future__ import print_function
from __future__ import division
import warnings

import pandas as pd
from autograd import numpy as np
from pandas import DataFrame
from autograd.scipy.special import gammaln


from . import BaseFitter
from ..utils import _check_inputs, _customer_lifetime_value


class GammaGammaFitter(BaseFitter):
    """
    Fitter for the gamma-gamma model.

    It is used to estimate the average monetary value of customer transactions.

    This implementation is based on the Excel spreadsheet found in [3]_.
    More details on the derivation and evaluation can be found in [4]_.

    Parameters
    ----------
    penalizer_coef: float
        The coefficient applied to an l2 norm on the parameters

    Attributes
    ----------
    penalizer_coef: float
github CamDavidsonPilon / lifetimes / lifetimes / fitters / pareto_nbd_fitter.py View on Github external
from __future__ import division

import pandas as pd
import numpy as np
from numpy import log, exp, logaddexp, asarray, any as npany
from pandas import DataFrame
from scipy.special import gammaln, hyp2f1, betaln
from scipy.special import logsumexp
from scipy.optimize import minimize

from lifetimes.fitters import BaseFitter
from lifetimes.utils import _check_inputs, _scale_time
from lifetimes.generate_data import pareto_nbd_model


class ParetoNBDFitter(BaseFitter):
    """
    Pareto NBD fitter [7]_.

    Parameters
    ----------
    penalizer_coef: float
        The coefficient applied to an l2 norm on the parameters

    Attributes
    ----------
    penalizer_coef: float
        The coefficient applied to an l2 norm on the parameters
    params_: :obj: OrderedDict
        The fitted parameters of the model
    data: :obj: DataFrame
        A DataFrame with the columns given in the call to `fit`