CamDavidsonPilon / lifetimes

Lifetime value in Python
MIT License
1.45k stars 373 forks source link

conditional_probability_of_being_alive_up_to_time #213

Closed xingzhex closed 4 years ago

xingzhex commented 5 years ago

Hello there, @CamDavidsonPilon . Prof. Fader and Hardie also calculated the probability that a customer will still be alive up to time T+t with the purchase history (x, t_x, T) using ParetoNBD model in this paper. Here I attached my code for this in case anyone is interested.

def conditional_probability_of_being_alive_up_to_time(
    self,
    t, 
    frequency, 
    recency, 
    T
):
    """
    Conditional probability of being alive up to time T+t.

    Compute the probability that a customer with history
    (frequency, recency, T) is still alive up to time T+t, given they have
        purchase history (frequency, recency, T).
    From paper:
    http://www.brucehardie.com/notes/015/additional_pareto_nbd_results.pdf

    Parameters
    ----------
    t: int
        time up to which probability should be calculated.            
    frequency: float
        historical frequency of customer.
    recency: float
        historical recency of customer.
    T: float
        age of the customer.
    Returns
    -------
    float
        value representing a probability
    """

    x, t_x = frequency, recency
    r, alpha, s, beta = self._unload_params('r', 'alpha', 's', 'beta')
    A_0 = self._log_A_0([r, alpha, s, beta], x, t_x, T)
    K_1 = s * log(beta + T + t) - s * log(beta + T)
    K_2 = log(s) - log(r + s + x) + (r + x) * log(alpha + T) + s * log(beta + T + t) + A_0

    return 1. / (exp(K_1) + exp(K_2))
psygo commented 4 years ago

Isn't this what this what the conditional_probability_alive() method does?

https://github.com/CamDavidsonPilon/lifetimes/blob/a1315dd93dd4381d3c607808bf5b76da9ffddc59/lifetimes/fitters/pareto_nbd_fitter.py#L288

lalit7jain commented 4 years ago

@psygo No I don't think the conditional_probability_alive function is similar to what @xingzhex has asked for. conditional_probability_alive this only works for detecting if a customer is alive as of today and not as of a time interval t. We definitely need this function to allow calculation in future period which in turn can help predict churn better.

jacobweiss2305 commented 2 years ago

Is this merged into the current code base? I am not finding it in the fitters files.

SSMK-wq commented 1 year ago

So, both lifetimes and btyd as of now doesn't have this feature to calculate churn at time T+t in future?

Is there any other way to find out the P(Alive) at time ((3rd month, 6 moth etc)

Is there anyway to sponsor for this feature (by paying 50 USD)?

ColtAllen commented 1 year ago

I was not intending to add this method to btyd until a future release because my current focus is on deprecating and/or updating the legacy lifetimes code before adding any enhancements, but if there is interest in doing so I can look into adding it for the next v0.1b3 release.

Is there any other way to find out the P(Alive) at time ((3rd month, 6 month etc)

I've found some other models that can do this like the Pareto/GGG and BG/NBD with time-varying covariates, but they won't be added to btyd until sometime next year.

SSMK-wq commented 1 year ago

Yes please. That would be great. You can let me know how i can pay 50 usd for it?

On Thu, 3 Nov 2022, 05:04 Colt Allen, @.***> wrote:

I was not intending to add this method to btyd https://github.com/ColtAllen/btyd until a future release because my current focus is on deprecating and/or updating the legacy lifetimes code before adding any enhancements, but if there is interest in doing so I can look into adding it for the next v0.1b3 release.

— Reply to this email directly, view it on GitHub https://github.com/CamDavidsonPilon/lifetimes/issues/213#issuecomment-1301253139, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHKM54JK6EU7TFX6AAOHBHTWGLJMPANCNFSM4FYR2XBA . You are receiving this because you commented.Message ID: @.***>

ColtAllen commented 1 year ago

Yes please. That would be great. You can let me know how i can pay 50 usd for it?

Don't worry about it; I've created a working branch and will start on it next week.

ColtAllen commented 1 year ago

This method was added to BTYD in https://github.com/ColtAllen/btyd/pull/67 as part of the v0.1b3 release.