Coder Social home page Coder Social logo

Comments (3)

mszep avatar mszep commented on June 3, 2024 2

For posterity: I have experienced the exact same problem, with a and b converging to values of 1e-6 and smaller. Fortunately I was able to stabilize the algorithm by setting initial values of 0.5 for each. My intuition is that very small initial values can trigger this problem, and maybe it would be sensible to set the random initialization to be 1.0 + uniform(0.05) rather than normal(mu=1.0, std=0.05) as I believe it is now.

from lifetimes.

rhydomako avatar rhydomako commented on June 3, 2024

Hi Marco,

I wasn't able to reproduce your findings. I ran a modified script to generate/fit a bunch of times:

import matplotlib.pylab as plt
import pandas as pd

import lifetimes.generate_data as gen
from lifetimes import estimation

T = 40
r = 0.24
alpha = 4.41
a = 0.8
b = 2.43

fitter = estimation.ModifiedBetaGeoFitter()

params = []
for _ in range(500):
    data = gen.modified_beta_geometric_nbd_model(T, r, alpha, a, b, size=1000)
    fitter.fit(data['frequency'],data['recency'],data['T'])

    params.append(fitter._unload_params('r','alpha','a','b'))

df = pd.DataFrame(params, columns=['r','alpha','a','b'])

fig, axes = plt.subplots(nrows=2, ncols=2)
df.hist('r', bins=100, range=(0,1), ax=axes[0,0])
df.hist('alpha', bins=100, range=(2,7), ax=axes[0,1])
df.hist('a', bins=100, range=(0.2,4), ax=axes[1,0])
df.hist('b', bins=100, range=(0,10), ax=axes[1,1])

which produced the following distributions:

download

I should note that I've clipped some outliers where sometimes the fitting failed and produced a and b params in the 10^6 range, but that happened something like 2 times in 500 trials.

I'm not sure why you're seeing so many fitted parameters close to zero...

from lifetimes.

CamDavidsonPilon avatar CamDavidsonPilon commented on June 3, 2024

Great script @rhydomako. I tried this too on my system (using 0.2.2.1). Output below:

screen shot 2016-10-12 at 19 41 07

I also get sometimes wild values for (a,b) (not shown here), but by adding a small penalizer_coef=0.01, the results are more sensible (below)

screen shot 2016-10-12 at 19 44 58

The max value of a in this simulation was 34.50

from lifetimes.

Related Issues (20)

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.