INNER CODE UNIT · Python

lambda_

CamDavidsonPilon/lifetimes · lifetimes/generate_data.py:43

    lambda_ = random.gamma(r, scale=1.0 / alpha, size=size)

    columns = ["frequency", "recency", "T", "lambda", "p", "alive", "customer_id"]
    df = pd.DataFrame(np.zeros((size, len(columns))), columns=columns)

    for i in range(size):
        p = probability_of_post_purchase_death[i]
        l = lambda_[i]

        # hacky until I can find something better
        times = []
        next_purchase_in = random.exponential(scale=1.0 / l)
        alive = True
        while (np.sum(times) + next_purchase_in < T[i]) and alive:
            times.append(next_purchase_in)
            next_purchase_in = random.exponential(scale=1.0 / l)
            alive = random.random() > p

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…