Giter VIP home page Giter VIP logo

shifted_beta_geometric_py's Introduction

sBG model of customer retention

A python implementation of the shifted-beta-geometric (sBG) model from Fader and Hardie's "How to Project Customer Retention" (2006).

Important note to modelers: amongst other presumptions, see §3 of the paper, sBG is only applicable to discrete, contractual customer relationships:

Custer Bases Diagram

Figure Source: "Probability Models for Customer-Base Analysis" (Fader and Hardie 2009)

Example

from shifted_beta_geometric import derl, fit, predicted_survival

# measured percentage of cohort that survives over time
example_data = [.869, .743, .653, .593, .551, .517, .491]

# fit our observed data to the sBG model, which returns the parameters alpha and beta
alpha, beta = fit(example_data)

# predict the next 5 time samples:
future = predicted_survival(alpha, beta, len(example_data) + 5)[-5:]

# future = [0.460, 0.436, 0.414, 0.395, 0.378]

# compute the discounted expected residual lifetime (DERL) for the survivors
# of this cohort at point in time t:
discount = 0.10  # rate at which we discount future revenue
                 # to get value in today's terms, e.g. 10%/year
t = len(example_data)
residual_cohort_lifetime = derl(alpha, beta, discount, t)

# residual_cohort_lifetime = 7.530

# if our average revenue per period per customer is a constant v_avg,
# to get the residual customer lifetime value (CLV) of this cohort
# we simply multiply the residual_cohort_lifetime by v_avg:

v_avg = 10
residual_cohort_clv = residual_cohort_lifetime * v_avg

# thus residual_cohort_clv = $75.30 per customer in this cohort

Requirements

sBG requires numpy and scipy for fitting and the gauss hypergeometric function.

shifted_beta_geometric_py's People

Contributors

jdmaturen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

shifted_beta_geometric_py's Issues

No module named 'sbg'

After installing
pip install git+https://github.com/jdmaturen/shifted_beta_geometric_py

python -c "from shifted_beta_geometric import fit"
Traceback (most recent call last):
File "", line 1, in
File "/Users/x/anaconda3/lib/python3.6/site-packages/shifted_beta_geometric/init.py", line 1, in
from sbg import derl
ModuleNotFoundError: No module named 'sbg'

probably because of wrong import namespace.

Different log-likelihood function

In the paper, the log likelihood is the sum of cancel rates times log probabilities, plus the end survived rate times final survivor likelihood. Should it therefore not be

def log_likelihood(alpha, beta, data, survivors=None):
    if alpha <= 0 or beta <= 0:
        return -1000
    if survivors is None:
        survivors = cancel_rates
    probabilities = generate_probabilities(alpha, beta, len(data))
    final_survivor_likelihood = survivor(probabilities, len(data) - 1)
    
    return sum([s * np.log(probabilities[t]) for t, s in enumerate(data)]) + survivors[-1] * np.log(final_survivor_likelihood)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.