Beta Survival Models: David Hubbard, Benoît Rostykus, Yves Raimond, Tony Jebara
Beta Survival Models: David Hubbard, Benoît Rostykus, Yves Raimond, Tony Jebara
Beta Survival Models: David Hubbard, Benoît Rostykus, Yves Raimond, Tony Jebara
α +β α +β
0.2 and the second moment as
t −1
α(α + 1) β(β + 1)
0 T = Ep(z) [z 2 ] = .
(α + β)(α + β + 1) (α + β)(α + β + 1)
Then, we approximate the distribution for the future event proba-
-0.2
bilities p(z) by a beta distribution where
(S − T )S
-0.4 α̂ =
T − S2
(7)
(S − T )(1 − S)
-0.6 βˆ = .
(T − S 2 )
-0.8 Therefore, in order to compare who is more likely to survive in
future horizons, we can combine Equation 7 and Equation 1 to find
-1 the median of the approximated future survival distribution.
0 0.2 0.4 0.6 0.8 1
p(3v > 3u ) Theorem 3.1. For random variables θu ∼ Beta(αu , βu ) and θv ∼
Beta(αv , βv ) for αu , αv , βu , βv ∈ N, p(θv > θu ) > 0.5 if and only if
I −1 (0.5, αv , βv ) > I −1 (0.5, αu , βu ) (the median of θv is larger than
Figure 2: The medians of beta distributions are consistent the median of θu ).
with the pairwise probabilistic ranking of beta distributions.
Proof. We first prove that the median gives the correct winner
under simplifying assumptions when both beta distributions have
this is given by the following integral: the same α or the same β.
∫ 1 ∫ 1 First consider when the distributions have the same αu = αv = α
θuαu −1 (1 − θu )βu −1 ·
1
p(θv > θu ) = and different βu and βv . In that case, Equation 6 simplifies to
θu =0 θv =θu B(α u , αv )
αÕ
v −1
B(αu + i, βu + βv )
θ αv −1 (1 − θv )βv −1dθu dθv
1
p(θv > θu ) = .
B(αv , αv ) v
(8)
i=0
(β v + i)B(1 + i, βv )B(α, βu )
which simplifies [18] into The formulas for p(θv > θu ) and p(θu > θv ) only differ in their
αÕ
v −1 denominators. Then, if βv > βu it is easy to show that
B(αu + i, βu + βv )
p(θv > θu ) = . (6)
i=0
(β v + i)B(1 + i, βv )B(αu , βu ) (βv + i)B(1 + i, βv )B(α, βu ) > (βu + i)B(1 + i, βu )B(α, βv ). (9)
If the quantity is larger than 0.5, then item u retains less than item Therefore, p(θv > θu ) > p(θu > θv ) if and only if βv > βu .
v in the first time step. It turns out, under thousands of simulations, Similarly, if βv > βu , the medians satisfy I −1 (0.5, αv , βv ) <
the less likely survivor is also the one with the larger median θ . I (0.5, αu , βu ). This is true since, if all else is equal, increasing the
−1
Figure 2 shows a scatter plot as we randomly compare pairs of beta β parameter reduces the median of a beta distribution. Therefore,
distributions. It is easy to see that the difference in their medians for αu = αv , the median ordering is always consistent with the
agrees with the probability p(θv > θu ). So, instead of using a probability test.
complicated formula to test p(θv > θu ), we just need to compare An analogous derivation holds when the two distributions have
the medians via the inverse incomplete beta function (betaincinv) the same βu = βv and different αu and αv . This is obtained by
denoted by I −1 () and see if I −1 (0.5, αu , βu ) > I −1 (0.5, αv , βv ). A using the property p(θ |α, β) = p(1 −θ |β, α). Therefore, for βu = βv ,
proof of this is below. the median ordering is always consistent with the probability test.
For later time steps, we will leverage a geometric assumption but Next we generalize these two statements to show that the median
applied to distributions rather than point estimates. The item which ordering always agrees with the probability test. Consider the situ-
retains longer is the one with the lower product of repeated coin ation where median(αu , βu ) > median(αu , βv ) > median(αv , βv ).
flip probabilities, i.e. p(θvt > θut ). In that case, the beta distributions Due to the scalar nature of the median of the beta distribution,
get modified by taking them to powers. Sometimes, the product we must have transitivity. We must also have median(αu , βu ) <
of beta-distributed random variables is beta-distributed [10] but median(αv , βu ) < median(αv , βv ). Since each pair of inequalities
4
on medians requires that the corresponding statement on the prob- α = 4.75, β = 14.25 α = 0.50, β = 1.50 α = 0.08, β = 0.25
1.0
ability tests also holds, the overall statement median(αu , βu ) <
median(αv , βv ) must also imply that p(θv > θu ) > p(θu > θv ). □ 0.8
Therefore, thanks to Theorem 3.1, we can safely rank order beta 0.6
S(t)
S(t)
S(t)
distributions simply by considering their medians. These rankings
0.4 θ̄
are not only pairwise consistent but globally consistent. Recall that
̄
S(t)
pairwise ranking of distributions does not always yield globally 0.2
̂
S(t)
consistent rankings as popularly highlighted through the study
0.0
of nontransitive dice [21]. Thus, given any beta distribution at a 0 5 10 0 5 10 0 5 10
particular horizon, it is straightforward to determine which items t t t
are most at risk through a simple sorting procedure on the medians.
Given this approach to ranking beta distributions, we can show Figure 3: Survival distributions as a function of time as well
the performance of our model-based ranking of users or items by as an estimate of S(t)
ˆ from the beta-logistic. Using a point-
holding out data and evaluating the time to event in terms of the estimate of the mean θ¯ (as in the logistic model) fails to re-
AUC (area under the curve) of the receiver operating characteristic cover the heterogeneity.
(ROC) curve.
4 EMPIRICAL RESULTS to the logistic model. However it seems to have a lower variance
4.1 Synthetic simulations which perhaps indicates that its posterior estimates are more con-
servative, a property which will be confirmed in the next set of
We present simulation results for the beta-logistic, and compare experiments.
them to the logistic model. We also show that the beta-logistic
successfully recovers the posterior for skewed distributions. In
our first simulation we have 3 beta distributions which have very Ex 0 Ex 1 Ex 2
different shapes (see table 1 below), but with the same mean (this
0.8
example is inspired by Fader and Hardie [9]). Here, each simulated
customer draws a coin from one of these distributions, and then 0.7
AUC
AUC
AUC
flips that coin repeatedly until they have an event or we reach a 0.6
censoring horizon (in this particular case we considered 4 decision
points). 0.5
0.4
shape α β µ 5 10 5 10 5 10
normal 4.75 14.25 0.25 time time time
right skewed 0.5 1.50 0.25
u shaped 0.083¯ 0.25 0.25
Figure 4: The level of heterogeneity increases from the left
Table 1: Heterogeneous beta distributions with identical panel to the right panel as we add a linear term in α. Clearly,
means. the mean of the beta-logistic 1 step (magenta plus), and lo-
gistic (cyan dot) are nearly identical, but the beta-logistic (or-
ange cross) considers more survival information and outper-
It is trivial to show that the logistic model will do no better forms both even when there is considerable homogeneity.
than random in this case, because it is not observing the dynamics
of the survival distribution which reveal the differing levels of
heterogeneity underlying the 3 populations. If we allow the beta- 4.2 Online conversions dataset
logistic model to have a dummy variable for each of these cases then
4.2.1 Survival modeling. We now evaluate the performance of the
it can recover the posterior of each (see Figure 3). This illustrates
beta logistic model on a large-scale sparse dataset. We use the
an important property of the beta-logistic: it recovers posterior
Criteo online conversions dataset published alongside [5] and pub-
estimates even when the data is very heterogeneous and allows us
licly available for download1 . We consider the problem of modeling
to fit survival distributions well.
the distribution of the time between a click event and a conver-
To create a slightly more realistic simulation, we can include
sion event. We will consider a censoring window of 12 hours (61%
another term which increases the homogeneity linearly in α and
of conversions happen within that window). As noted in [5], the
we add this as another covariate in the models. We also inject ex-
exponential distribution fits reasonably well the data so we will
ponential noise into the α and β used for our random draws. Now,
compare the beta-logistic model against the exponential distribu-
the logistic model does do better than random when there is homo-
tion (1 parameter) and the Weibull distribution (2 parameters). Since
geneity present (see Figure 4), however it still leaves signal behind
the temporal integration of the beta-logistic model is intrinsically
by not considering the survival distribution. We additionally show
results for a one time step beta logistic which performs similarly 1 http://labs.criteo.com/2013/12/conversion-logs-dataset/
5
discrete, we consider a time-discretization of 5 minute steps. We model, the prediction variance on datapoint x is given by:
also add as baselines 2 logistic models: one trained at a horizon of α(x)β(x)
5 minutes (the shortest interval), and one trained at a horizon of 12 Var(x) = .
(α(x) + β(x))2 (α(x) + β(x) + 1)
hours (the largest window). All conditional models are implemented
as sparse linear models in Vectorflow [19] and trained through sto- For a logistic model parameterized by θ ∈ Rd , a standard way
chastic gradient descent. All survival models use an exponential to estimate the confidence of a prediction is through the Laplace
reparameterization of their parameters (since the beta, exponential, approximation of its posterior [17]. In the high-dimensional set-
and Weibull distributions all require positivity in their parameters). ting, estimating the Hessian or its inverse become impractical tasks
Censored events are down-sampled by a factor of 10x. We use 1M (storage cost is O(d 2 ) and matrix inversion requires O(d 3 ) compu-
rows for training and 1M (held-out in time) rows for evaluation. tation). In this scenario, it is customary to assume independence
The total (covariate) dimensionality of the problem is 102K after of the posterior coordinates and restrict the estimation to the di-
agonal of the Hessian h = 2 ∈ Rd , which reduces both storage
one-hot-encoding. Note that covariates are sparse and the overall 1
sparsity of the problem is over 99.98%. Results are presented in σ
and computation costs to O(d). Hence under this assumption, for a
Figure 5.
given datapoint x the distribution of possible values for the random
variable Y = θ T x is also Gaussian with parameters:
!
Õ Õ
N θi xi , σi2x i2 .
i i
If the full Hessian inverse H −1 is estimated, then Y is Gaussian with
parameters:
N θ · x, x T · H −1x) .
0 5 CONCLUSION
0.0 0.2 0.4 0.6 0.8 1.0
θ
We noted that heterogeneity in the beta-logistic model can better
capture the temporal effects of survival and ranking at multiple
horizons. We extended the beta-logistic and its maximum likelihood
Figure 7: Estimated churn probabilities for 3 different co- estimation to linear, tree and neural models as well as characterized
horts. The large variations in the shape of the fitted distri- the convexity and properties of the learning problem. The resulting
butions motivate the use of a beta prior on the conditional survival models give survival estimates and provably consistent
churn probability. rankings of who is most-at-risk at multiple time horizons. Empirical
7
[11] Andrew Gelman, Hal S Stern, John B Carlin, David B Dunson, Aki Vehtari, and
Donald B Rubin. 2013. Bayesian data analysis. Chapman and Hall/CRC.
[12] Sunil Gupta, Dominique Hanssens, Bruce Hardie, William Kahn, V. Kumar,
Nathaniel Lin, Nalini Ravishanker, and S. Sriram. 2006. Modeling customer
lifetime value. Journal of Service Research 9, 2 (2006).
logistic 8ep [13] James J Heckman and Robert J Willis. 1977. A Beta-logistic Model for the Analysis
of Sequential Labor Force Participation by Married Women. Journal of Political
AUC
logistic 1ep
Economy 85, 1 (1977), 27–58.
beta-logistic [14] John D Kalbfleisch and Ross L Prentice. 2011. The statistical analysis of failure
time data. Vol. 360. John Wiley & Sons.
[15] Guolin Ke, Qi Meng, Thomas Finley, Taifeng Wang, Wei Chen, Weidong Ma,
Qiwei Ye, and Tie-Yan Liu. 2017. Lightgbm: A highly efficient gradient boosting
decision tree. In Advances in Neural Information Processing Systems. 3146–3154.
[16] Lihong Li, Wei Chu, John Langford, Taesup Moon, and Xuanhui Wang. 2012.
1 2 3 4 5 6 7 8 9 An unbiased offline evaluation of contextual bandit algorithms with generalized
completed episodes linear models. In Proceedings of the Workshop on On-line Trading of Exploration
and Exploitation 2. 19–36.
[17] David JC MacKay. 2003. Information theory, inference and learning algorithms.
Cambridge university press.
Figure 9: The beta-logistic improves ranking accuracy (in [18] Evan Miller. 2015. Bayesian AB Testing. http://www.evanmiller.org/
terms of AUC) for early horizons. bayesian-ab-testing.html#cite1
[19] Benoît Rostykus and Yves Raimond. 2018. vectorflow: a minimalist neural-
network library. SysML (2018).
[20] Cynthia Rudin, David Waltz, Roger N. Anderson, Albert Boulanger, Ansaf Salleb-
Aouissi, Maggie Chow, Haimonti Dutta, Philip Gross, Bert Huang, Steve Ierome,
results demonstrate that the beta-logistic is an effective model in Delfina Isaac, Arthur Kressner, Rebecca J. Passonneau, Axinia Radeva, and Leon
discrete time to event problems, and improves over common base- Wu. 2012. Machine Learning for the New York City Power Grid. IEEE Transactions
on Pattern Analysis and Machine Intelligence 34, 2 (February 2012), 328–345.
lines. It seems that in practice regardless of how many attributes are [21] Richard P. Savage. 1994. The Paradox of Nontransitive Dice. The American
considered there are still unobserved variations between individu- Mathematical Monthly 101, 5 (1994).
als that influence the time to event. Further we demonstrated that [22] James W. Vaupel and Anatoliy Yashin. 1985. Heterogeneity’s Ruses: Some Sur-
prising Effects of Selection on Population Dynamics. The American statistician
we can recover posteriors effectively even when the data is very 39 (09 1985), 176–85. https://doi.org/10.1080/00031305.1985.10479424
heterogeneous, and due to the speed and ease of implementation we
argue that the beta-logistic is a baseline that should be considered
in time to event problems in practice. A BETA LOGISTIC FORMULAS
In future work, we plan to study the potential use of the beta- A.1 Recurrence derivation
logistic in explore-exploit scenarios and as a viable option in rein- This derivation is taken from Fader and Hardie [8] where they use
forcement learning to model long-term consequences from near- it as a cohort model (also called the shifted beta geometric model)
term decisions and observations. that is not conditional on a covariate vector x.
We do not observe θ , but its expectation given the beta prior
ACKNOWLEDGMENTS (also called marginal likelihood) is given by:
The authors would like to thank Nikos Vlassis for his helpful com-
θ α −1 (1 − θ )β −1
∫ 1
ments during the development of this work, and Harald Steck for P(T = t |α, β) = θ (1 − θ )t −1 dθ
his thoughtful review and guidance. 0 B(α, β)
B(α + 1, β + t − 1)
=
REFERENCES B(α, β)
[1] Martín Abadi, Paul Barham, Jianmin Chen, Zhifeng Chen, Andy Davis, Jeffrey
Dean, Matthieu Devin, Sanjay Ghemawat, Geoffrey Irving, Michael Isard, et al. We can write the above as:
[n. d.]. Tensorflow: a system for large-scale machine learning.
Γ(α + β) ∗ Γ(α + 1) ∗ Γ(β + t − 1)
[2] Yoram Ben-Porath. 1973. Labor-force participation rates and the supply of labor.
P(T = t |α, β) = .
Journal of Political economy 81, 3 (1973), 697–704. Γ(α) ∗ Γ(β) ∗ Γ(α + β + t)
[3] James O Berger. 2013. Statistical decision theory and Bayesian analysis. Springer
Science & Business Media.
[4] Allison Chang, Cynthia Rudin, Michael Cavaretta, Robert Thomas, and Gloria
Using the property Γ(z + 1) = zΓ(z) leads to equations (3) and (4),
Chou. 2012. How to Reverse-Engineer Quality Rankings. Machine Learning 88 and at t = 1 we have
(September 2012), 369–398. Issue 3.
Γ(α + β) ∗ Γ(α + 1) ∗ Γ(β)
P(T = 1|α, β) =
[5] Olivier Chapelle. 2014. Modeling delayed feedback in display advertising. In
Proceedings of the 20th ACM SIGKDD international conference on Knowledge Γ(α) ∗ Γ(β) ∗ Γ(α + β + 1)
discovery and data mining. ACM, 1097–1105.
α
[6] Tianqi Chen and Carlos Guestrin. 2016. Xgboost: A scalable tree boosting system. P(T = 1|α, β) =
In Proceedings of the 22nd acm sigkdd international conference on knowledge α +β
discovery and data mining. ACM, 785–794.
[7] David R Cox. 1972. Regression models and life-tables. Journal of the Royal
Statistical Society: Series B (Methodological) 34, 2 (1972), 187–202. A.2 Gradients
[8] Peter S Fader and Bruce GS Hardie. 2007. How to project customer retention.
Journal of Interactive Marketing 21, 1 (2007), 76–90.
Note that for machine learning libraries that do not offer symbolic
[9] Peter S Fader, Bruce GS Hardie, Yuzhou Liu, Joseph Davin, and Thomas Steen- computation and auto-differentiation, taking the −loд of equations
burgh. 2018. "How to Project Customer Retention" Revisited: The Role of Duration (3) and (4) and differentiating leads to the following recurrence for-
Dependence. Journal of Interactive Marketing 43 (2018), 1–16.
[10] Da-Yin Fan. 1991. The distribution of the product of independent beta variables. mulas for the gradient of the loss function on a given data point with
Communications in Statistics-Theory and Methods 20, 12 (1991), 4043–4052. respect to the output parameters ai and bi of the model considered:
8
!
∂ 2 log(P(T > t)) ∂ 2 log(P(T > t − 1)) ∂ 2a α
∂ log(P(T = 1)) ∂a β
= −
= ∂ai2 ∂ai2 ∂ai2 α + β + t − 1
∂ai ∂ai α + β
∂a 2 β +t −1
∂ log(P(T = 1)) ∂b β α
−
=− ∂ai (α + β + t − 1)2
∂bi ∂bi α + β
∂ 2 log(P(T > t)) ∂ 2 log(P(T > t − 1))
These derivatives expand as follows: =
∂bi2 ∂b 2
∂ log(P(T = t)) ∂ log(P(T = t − 1)) ∂a α ! i
= − ∂ 2b αβ
∂ai ∂ai ∂ai α + β + t − 1 +
∂ log(P(T = t)) ∂ log(P(T = t − 1)) ∂bi2 (β + t − 1)(α + β + t − 1)
=
∂bi ∂bi ∂b 2 β 2 − (t − 1)(α + t − 1)
+ β α
∂b (α + 1)β ∂bi
+ (β + t − 1)2 (α + β + t − 1)2
∂bi (β + t − 2)(α + β + t − 1)
B ALTERNATIVE DERIVATION
We can get a similar recursion for the survival function:
Another intuitive derivation of the single-step beta-logistic is ob-
∂ log(P(T > 1)) ∂a α
=− tained by starting from the likelihood for a logistic model and
∂ai ∂ai α + β modeling the probabilities with a beta distribution:
∂ log(P(T > 1)) ∂b α
P(yi = 1|α, β)yi (1 − P(yi = 1|α, β))yi −1
Ö
= L=
∂bi ∂bi α + β i
Ö Ö
∂ log(P(T > t)) ∂ log(P(T > t − 1)) ∂a α = P(yi = 1|α, β) (1 − P(yi = 1|α, β))
= − ∀yi =1 ∀yi =0
∂ai ∂ai ∂ai α + β + t − 1 Ö Ö
∂ log(P(T > t)) ∂ log(P(T > t − 1)) = P(T = 1|α, β) P(t >= 1|α, β).
=
∂bi ∂bi uncensor ed censor ed
∂b αβ
This is exactly the survival likelihood for a 1 step beta logistic
+
∂bi (β + t − 1)(α + β + t − 1) model.
def h e s s _ B L ( a l p h a , b e t a , t , i s _ c e n s o r e d ) :
"""
This f u n c t i o n computes the diagonal of the Hessian of the beta l o g i s t i c o b j e c t i v e .
"""
N = len ( a l p h a )
h = np . z e r o s ( ( N , 2 ) )
f o r j in range ( 0 , N ) :
h [ j : ] = −alpha [ j ] ∗ beta [ j ] / ( ( alpha [ j ] + beta [ j ] ) ∗ ∗ 2 )
i f ( not i s _ c e n s o r e d [ j ] ) :
# failed
f o r i in range ( 2 , i n t ( t [ j ] + 1 ) ) :
h [ j , 0 ] += − a l p h a [ j ] ∗ ( ( b e t a [ j ] + i − 1 ) / ( a l p h a [ j ] + b e t a [ j ] + i − 1 ) ∗ ∗ 2 )
d = ( beta [ j ] + i − 2 ) ∗ ∗ 2 ) ∗ ( alpha [ j ] + beta [ j ] + i − 1 ) ∗ ∗ 2 )
h [ j , 1 ] += b e t a [ j ] ∗ ( ( a l p h a [ j ] + 1 ) ∗ ( b e t a [ j ] ∗ ∗ 2 − ( i − 2 ) ∗ ( a l p h a [ j ]+ i − 1 ) / d
else :
# survived
f o r i in range ( 2 , i n t ( t [ j ] + 1 ) ) :
h [ j , 0 ] += − a l p h a [ j ] ∗ ( ( b e t a [ j ] + i − 1 ) / ( a l p h a [ j ] + b e t a [ j ] + i − 1 ) ∗ ∗ 2 )
d = ( beta [ j ] + i − 2 ) ∗ ∗ 2 ) ∗ ( alpha [ j ] + beta [ j ] + i − 1 ) ∗ ∗ 2 )
h [ j , 1 ] += b e t a [ j ] ∗ ( ( a l p h a [ j ] ) ∗ ( b e t a [ j ] ∗ ∗ 2 − ( i − 1 ) ∗ ( a l p h a [ j ]+ i − 1 ) / d
h . shape = (N∗ 2 )
return h
10
def l i k e l i h o o d _ B L ( a l p h a , b e t a , t , i s _ c e n s o r e d ) :
"""
This f u n c t i o n computes beta l o g i s t i c o b j e c t i v e ( l i k e l i h o o d : higher = b e t t e r )
S i n c e i t i s h e a v i l y v e c t o r i z e d i n p r a c t i c e f o r p e r f o r m a n c e r e a s o n s , we w r i t e
h e r e t h e non − v e c t o r i z e d v e r s i o n f o r r e a d a b i l i t y :
"""
p = alpha / ( alpha + beta )
s = 1 − p
f o r j in range ( 0 , len ( a l p h a ) ) :
f o r i in range ( 2 , i n t ( t [ j ] + 1 ) ) :
p[ j ] = p[ j ] ∗ ( beta [ j ] + i − 2 ) / ( alpha [ j ] + beta [ j ] + i − 1)
s [ j ] = s [ j ] − p[ j ]
return p ∗ ( 1 . 0 − i s _ c e n s o r e d ) + s ∗ i s _ c e n s o r e d
11