INNER CODE UNIT · Python

alive

CamDavidsonPilon/lifetimes · lifetimes/generate_data.py:253

        alive = random.random() > p  # essentially the difference between this model and BG/NBD
        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

        times = np.array(times).cumsum()
        df.iloc[i] = (
            np.unique(np.array(times).astype(int)).shape[0],
            np.max(times if times.shape[0] > 0 else 0),
            T[i],
            l,
            p,
            alive,
            i,
        )

    return df.set_index("customer_id")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…