## 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. CamDavidsonPilon / lifetimes / lifetimes / fitters / beta_geo_fitter.py View on Github ``````from __future__ import print_function
from __future__ import division
import warnings

import pandas as pd
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 _, 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

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

import numpy as np
import pandas as pd
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 _.

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`````` CamDavidsonPilon / lifetimes / lifetimes / fitters / gamma_gamma_fitter.py View on Github ``````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 . import BaseFitter

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 _.
More details on the derivation and evaluation can be found in _.

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

Attributes
----------
penalizer_coef: float`````` CamDavidsonPilon / lifetimes / lifetimes / fitters / pareto_nbd_fitter.py View on Github ``````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

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

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``````` GitHub MIT Latest version published 3 years ago