Probabilistic customer attrition models predict in general three expected characteristics for every customer:

  • "conditional expected transactions" (CET), which is the number of transactions to expect from a customer during the prediction period,

  • "probability of a customer being alive" (PAlive) at the end of the estimation period and

  • "discounted expected residual transactions" (DERT) for every customer, which is the total number of transactions for the residual lifetime of a customer discounted to the end of the estimation period. In the case of time-varying covariates, instead of DERT, "discounted expected conditional transactions" (DECT) is predicted. DECT does only cover a finite time horizon in contrast to DERT. For continuous.discount.factor=0, DECT corresponds to CET.

In order to derive a monetary value such as CLV, customer spending has to be considered. If the clv.data object contains spending information, customer spending can be predicted using a Gamma/Gamma spending model for parameter predict.spending and the predicted CLV is be calculated (if the transaction model supports DERT/DECT). In this case, the prediction additionally contains the following two columns:

  • "predicted.mean.spending", the mean spending per transactions as predicted by the spending model.

  • "CLV", the customer lifetime value. CLV is the product of DERT/DECT and predicted spending.

# S3 method for clv.fitted.transactions
predict(
  object,
  newdata = NULL,
  prediction.end = NULL,
  predict.spending = gg,
  continuous.discount.factor = 0.1,
  verbose = TRUE,
  ...
)

# S4 method for clv.fitted.transactions
predict(
  object,
  newdata = NULL,
  prediction.end = NULL,
  predict.spending = gg,
  continuous.discount.factor = 0.1,
  verbose = TRUE,
  ...
)

Arguments

object

A fitted clv transaction model for which prediction is desired.

newdata

A clv data object for which predictions should be made with the fitted model. If none or NULL is given, predictions are made for the data on which the model was fit.

prediction.end

Until what point in time to predict. This can be the number of periods (numeric) or a form of date/time object. See details.

predict.spending

Whether and how to predict spending and based on it also CLV, if possible. See details.

continuous.discount.factor

continuous discount factor to use to calculate DERT/DECT

verbose

Show details about the running of the function.

...

Ignored

Value

An object of class data.table with columns:

Id

The respective customer identifier

period.first

First timepoint of prediction period

period.last

Last timepoint of prediction period

period.length

Number of time units covered by the period indicated by period.first and period.last (including both ends).

PAlive

Probability to be alive at the end of the estimation period

CET

The Conditional Expected Transactions

DERT or DECT

Discounted Expected Residual Transactions or Discounted Expected Conditional Transactions for dynamic covariates models

actual.x

Actual number of transactions until prediction.end. Only if there is a holdout period and the prediction ends in it, otherwise it is not reported.

actual.total.spending

Actual total spending until prediction.end. Only if there is a holdout period and the prediction ends in it, otherwise it is not reported.

predicted.mean.spending

The mean spending per transactions as predicted by the spending model.

predicted.CLV

Customer Lifetime Value based on DERT/DECT and predicted.mean.spending.

Details

predict.spending indicates whether to predict customers' spending and if so, the spending model to use. Accepted inputs are either a logical (TRUE/FALSE), a method to fit a spending model (i.e. gg), or an already fitted spending model. If provided TRUE, a Gamma-Gamma model is fit with default options. If argument newdata is provided, the spending model is fit on newdata. Predicting spending is only possible if the transaction data contains spending information. See examples for illustrations of valid inputs.

The newdata argument has to be a clv data object of the exact same class as the data object on which the model was fit. In case the model was fit with covariates, newdata needs to contain identically named covariate data.

The use case for newdata is mainly two-fold: First, to estimate model parameters only on a sample of the data and then use the fitted model object to predict or plot for the full data set provided through newdata. Second, for models with dynamic covariates, to provide a clv data object with longer covariates than contained in the data on which the model was estimated what allows to predict or plot further. When providing newdata, some models might require additional steps that can significantly increase runtime.

prediction.end indicates until when to predict or plot and can be given as either a point in time (of class Date, POSIXct, or character) or the number of periods. If prediction.end is of class character, the date/time format set when creating the data object is used for parsing. If prediction.end is the number of periods, the end of the fitting period serves as the reference point from which periods are counted. Only full periods may be specified. If prediction.end is omitted or NULL, it defaults to the end of the holdout period if present and to the end of the estimation period otherwise.

The first prediction period is defined to start right after the end of the estimation period. If for example weekly time units are used and the estimation period ends on Sunday 2019-01-01, then the first day of the first prediction period is Monday 2019-01-02. Each prediction period includes a total of 7 days and the first prediction period therefore will end on, and include, Sunday 2019-01-08. Subsequent prediction periods again start on Mondays and end on Sundays. If prediction.end indicates a timepoint on which to end, this timepoint is included in the prediction period.

continuous.discount.factor is the continuous rate used to discount the expected residual transactions (DERT/DECT). An annual rate of (100 x d)% equals a continuous rate delta = ln(1+d). To account for time units which are not annual, the continuous rate has to be further adjusted to delta=ln(1+d)/k, where k are the number of time units in a year.

See also

models to predict transactions: pnbd, bgnbd, ggomnbd.

models to predict spending: gg.

predict for spending models

Examples


# \donttest{

data("apparelTrans")
# Fit pnbd standard model on data, WITH holdout
apparel.holdout <- clvdata(apparelTrans, time.unit="w",
                           estimation.split=37, date.format="ymd")
apparel.pnbd <- pnbd(apparel.holdout)
#> Starting estimation...
#> Estimation finished!

# Predict until the end of the holdout period
predict(apparel.pnbd)
#> Predicting from 2005-09-20 until (incl.) 2006-07-16 (42.86 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#>        Id period.first period.last period.length actual.x actual.total.spending
#>   1:    1   2005-09-20  2006-07-16      42.85714        0                  0.00
#>   2:   10   2005-09-20  2006-07-16      42.85714        0                  0.00
#>   3:  100   2005-09-20  2006-07-16      42.85714       23                737.53
#>   4: 1000   2005-09-20  2006-07-16      42.85714       25               1120.41
#>   5: 1001   2005-09-20  2006-07-16      42.85714       11                364.00
#>  ---                                                                           
#> 246: 1219   2005-09-20  2006-07-16      42.85714       14                413.76
#> 247:  122   2005-09-20  2006-07-16      42.85714        0                  0.00
#> 248: 1220   2005-09-20  2006-07-16      42.85714        0                  0.00
#> 249: 1221   2005-09-20  2006-07-16      42.85714        9                302.65
#> 250: 1222   2005-09-20  2006-07-16      42.85714        0                  0.00
#>         PAlive       CET       DERT predicted.mean.spending predicted.CLV
#>   1: 0.3909507  0.269518 0.06742987                40.39473      2.723811
#>   2: 0.4683642  1.145548 0.28660121                57.49121     16.477049
#>   3: 0.9858258 16.263678 4.06895942                43.83628    178.368045
#>   4: 0.9948488 12.917715 3.23184305                43.46097    140.459030
#>   5: 0.6492950  5.009457 1.25330058                46.17636     57.872865
#>  ---                                                                     
#> 246: 0.9859138  4.143114 1.03655278                33.20726     34.421081
#> 247: 0.3909507  0.269518 0.06742987                40.39473      2.723811
#> 248: 0.3909507  0.269518 0.06742987                40.39473      2.723811
#> 249: 0.9762838  4.960046 1.24093869                34.00868     42.202689
#> 250: 0.4471937  0.701030 0.17538854                48.80122      8.559174

# Predict until 10 periods (weeks in this case) after
#   the end of the 37 weeks fitting period
predict(apparel.pnbd, prediction.end = 10) # ends on 2010-11-28
#> Predicting from 2005-09-20 until (incl.) 2005-11-28 (10 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#>        Id period.first period.last period.length actual.x actual.total.spending
#>   1:    1   2005-09-20  2005-11-28            10        0                  0.00
#>   2:   10   2005-09-20  2005-11-28            10        0                  0.00
#>   3:  100   2005-09-20  2005-11-28            10        6                134.15
#>   4: 1000   2005-09-20  2005-11-28            10        9                318.20
#>   5: 1001   2005-09-20  2005-11-28            10        3                118.22
#>  ---                                                                           
#> 246: 1219   2005-09-20  2005-11-28            10        3                 93.92
#> 247:  122   2005-09-20  2005-11-28            10        0                  0.00
#> 248: 1220   2005-09-20  2005-11-28            10        0                  0.00
#> 249: 1221   2005-09-20  2005-11-28            10        4                 91.80
#> 250: 1222   2005-09-20  2005-11-28            10        0                  0.00
#>         PAlive        CET       DERT predicted.mean.spending predicted.CLV
#>   1: 0.3909507 0.06948088 0.06742987                40.39473      2.723811
#>   2: 0.4683642 0.29531878 0.28660121                57.49121     16.477049
#>   3: 0.9858258 4.19272526 4.06895942                43.83628    178.368045
#>   4: 0.9948488 3.33014626 3.23184305                43.46097    140.459030
#>   5: 0.6492950 1.29142232 1.25330058                46.17636     57.872865
#>  ---                                                                      
#> 246: 0.9859138 1.06808168 1.03655278                33.20726     34.421081
#> 247: 0.3909507 0.06948088 0.06742987                40.39473      2.723811
#> 248: 0.3909507 0.06948088 0.06742987                40.39473      2.723811
#> 249: 0.9762838 1.27868441 1.24093869                34.00868     42.202689
#> 250: 0.4471937 0.18072335 0.17538854                48.80122      8.559174

# Predict until 31th Dec 2016 with the timepoint as a character
predict(apparel.pnbd, prediction.end = "2016-12-31")
#> Predicting from 2005-09-20 until (incl.) 2016-12-31 (588.71 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#>        Id period.first period.last period.length    PAlive        CET
#>   1:    1   2005-09-20  2016-12-31      588.7143 0.3909507   2.095867
#>   2:   10   2005-09-20  2016-12-31      588.7143 0.4683642   8.908191
#>   3:  100   2005-09-20  2016-12-31      588.7143 0.9858258 126.472146
#>   4: 1000   2005-09-20  2016-12-31      588.7143 0.9948488 100.452740
#>   5: 1001   2005-09-20  2016-12-31      588.7143 0.6492950  38.955319
#>  ---                                                                 
#> 246: 1219   2005-09-20  2016-12-31      588.7143 0.9859138  32.218324
#> 247:  122   2005-09-20  2016-12-31      588.7143 0.3909507   2.095867
#> 248: 1220   2005-09-20  2016-12-31      588.7143 0.3909507   2.095867
#> 249: 1221   2005-09-20  2016-12-31      588.7143 0.9762838  38.571085
#> 250: 1222   2005-09-20  2016-12-31      588.7143 0.4471937   5.451459
#>            DERT predicted.mean.spending predicted.CLV
#>   1: 0.06742987                40.39473      2.723811
#>   2: 0.28660121                57.49121     16.477049
#>   3: 4.06895942                43.83628    178.368045
#>   4: 3.23184305                43.46097    140.459030
#>   5: 1.25330058                46.17636     57.872865
#>  ---                                                 
#> 246: 1.03655278                33.20726     34.421081
#> 247: 0.06742987                40.39473      2.723811
#> 248: 0.06742987                40.39473      2.723811
#> 249: 1.24093869                34.00868     42.202689
#> 250: 0.17538854                48.80122      8.559174

# Predict until 31th Dec 2016 with the timepoint as a Date
predict(apparel.pnbd, prediction.end = lubridate::ymd("2016-12-31"))
#> Predicting from 2005-09-20 until (incl.) 2016-12-31 (588.71 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#>        Id period.first period.last period.length    PAlive        CET
#>   1:    1   2005-09-20  2016-12-31      588.7143 0.3909507   2.095867
#>   2:   10   2005-09-20  2016-12-31      588.7143 0.4683642   8.908191
#>   3:  100   2005-09-20  2016-12-31      588.7143 0.9858258 126.472146
#>   4: 1000   2005-09-20  2016-12-31      588.7143 0.9948488 100.452740
#>   5: 1001   2005-09-20  2016-12-31      588.7143 0.6492950  38.955319
#>  ---                                                                 
#> 246: 1219   2005-09-20  2016-12-31      588.7143 0.9859138  32.218324
#> 247:  122   2005-09-20  2016-12-31      588.7143 0.3909507   2.095867
#> 248: 1220   2005-09-20  2016-12-31      588.7143 0.3909507   2.095867
#> 249: 1221   2005-09-20  2016-12-31      588.7143 0.9762838  38.571085
#> 250: 1222   2005-09-20  2016-12-31      588.7143 0.4471937   5.451459
#>            DERT predicted.mean.spending predicted.CLV
#>   1: 0.06742987                40.39473      2.723811
#>   2: 0.28660121                57.49121     16.477049
#>   3: 4.06895942                43.83628    178.368045
#>   4: 3.23184305                43.46097    140.459030
#>   5: 1.25330058                46.17636     57.872865
#>  ---                                                 
#> 246: 1.03655278                33.20726     34.421081
#> 247: 0.06742987                40.39473      2.723811
#> 248: 0.06742987                40.39473      2.723811
#> 249: 1.24093869                34.00868     42.202689
#> 250: 0.17538854                48.80122      8.559174


# Predict future transactions but not spending and CLV
predict(apparel.pnbd, predict.spending = FALSE)
#> Predicting from 2005-09-20 until (incl.) 2006-07-16 (42.86 Weeks).
#>        Id period.first period.last period.length actual.x actual.total.spending
#>   1:    1   2005-09-20  2006-07-16      42.85714        0                  0.00
#>   2:   10   2005-09-20  2006-07-16      42.85714        0                  0.00
#>   3:  100   2005-09-20  2006-07-16      42.85714       23                737.53
#>   4: 1000   2005-09-20  2006-07-16      42.85714       25               1120.41
#>   5: 1001   2005-09-20  2006-07-16      42.85714       11                364.00
#>  ---                                                                           
#> 246: 1219   2005-09-20  2006-07-16      42.85714       14                413.76
#> 247:  122   2005-09-20  2006-07-16      42.85714        0                  0.00
#> 248: 1220   2005-09-20  2006-07-16      42.85714        0                  0.00
#> 249: 1221   2005-09-20  2006-07-16      42.85714        9                302.65
#> 250: 1222   2005-09-20  2006-07-16      42.85714        0                  0.00
#>         PAlive       CET       DERT
#>   1: 0.3909507  0.269518 0.06742987
#>   2: 0.4683642  1.145548 0.28660121
#>   3: 0.9858258 16.263678 4.06895942
#>   4: 0.9948488 12.917715 3.23184305
#>   5: 0.6492950  5.009457 1.25330058
#>  ---                               
#> 246: 0.9859138  4.143114 1.03655278
#> 247: 0.3909507  0.269518 0.06742987
#> 248: 0.3909507  0.269518 0.06742987
#> 249: 0.9762838  4.960046 1.24093869
#> 250: 0.4471937  0.701030 0.17538854

# Predict spending by fitting a Gamma-Gamma model
predict(apparel.pnbd, predict.spending = gg)
#> Predicting from 2005-09-20 until (incl.) 2006-07-16 (42.86 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#>        Id period.first period.last period.length actual.x actual.total.spending
#>   1:    1   2005-09-20  2006-07-16      42.85714        0                  0.00
#>   2:   10   2005-09-20  2006-07-16      42.85714        0                  0.00
#>   3:  100   2005-09-20  2006-07-16      42.85714       23                737.53
#>   4: 1000   2005-09-20  2006-07-16      42.85714       25               1120.41
#>   5: 1001   2005-09-20  2006-07-16      42.85714       11                364.00
#>  ---                                                                           
#> 246: 1219   2005-09-20  2006-07-16      42.85714       14                413.76
#> 247:  122   2005-09-20  2006-07-16      42.85714        0                  0.00
#> 248: 1220   2005-09-20  2006-07-16      42.85714        0                  0.00
#> 249: 1221   2005-09-20  2006-07-16      42.85714        9                302.65
#> 250: 1222   2005-09-20  2006-07-16      42.85714        0                  0.00
#>         PAlive       CET       DERT predicted.mean.spending predicted.CLV
#>   1: 0.3909507  0.269518 0.06742987                40.39473      2.723811
#>   2: 0.4683642  1.145548 0.28660121                57.49121     16.477049
#>   3: 0.9858258 16.263678 4.06895942                43.83628    178.368045
#>   4: 0.9948488 12.917715 3.23184305                43.46097    140.459030
#>   5: 0.6492950  5.009457 1.25330058                46.17636     57.872865
#>  ---                                                                     
#> 246: 0.9859138  4.143114 1.03655278                33.20726     34.421081
#> 247: 0.3909507  0.269518 0.06742987                40.39473      2.723811
#> 248: 0.3909507  0.269518 0.06742987                40.39473      2.723811
#> 249: 0.9762838  4.960046 1.24093869                34.00868     42.202689
#> 250: 0.4471937  0.701030 0.17538854                48.80122      8.559174

# Fit a spending model separately and use it to predict spending
apparel.gg <- gg(apparel.holdout, remove.first.transaction = FALSE)
#> Starting estimation...
#> Estimation finished!
predict(apparel.pnbd, predict.spending = apparel.gg)
#> Predicting from 2005-09-20 until (incl.) 2006-07-16 (42.86 Weeks).
#>        Id period.first period.last period.length actual.x actual.total.spending
#>   1:    1   2005-09-20  2006-07-16      42.85714        0                  0.00
#>   2:   10   2005-09-20  2006-07-16      42.85714        0                  0.00
#>   3:  100   2005-09-20  2006-07-16      42.85714       23                737.53
#>   4: 1000   2005-09-20  2006-07-16      42.85714       25               1120.41
#>   5: 1001   2005-09-20  2006-07-16      42.85714       11                364.00
#>  ---                                                                           
#> 246: 1219   2005-09-20  2006-07-16      42.85714       14                413.76
#> 247:  122   2005-09-20  2006-07-16      42.85714        0                  0.00
#> 248: 1220   2005-09-20  2006-07-16      42.85714        0                  0.00
#> 249: 1221   2005-09-20  2006-07-16      42.85714        9                302.65
#> 250: 1222   2005-09-20  2006-07-16      42.85714        0                  0.00
#>         PAlive       CET       DERT predicted.mean.spending predicted.CLV
#>   1: 0.3909507  0.269518 0.06742987                70.27718      4.738781
#>   2: 0.4683642  1.145548 0.28660121                61.78767     17.708422
#>   3: 0.9858258 16.263678 4.06895942                42.33307    172.251543
#>   4: 0.9948488 12.917715 3.23184305                41.93464    135.526187
#>   5: 0.6492950  5.009457 1.25330058                45.28636     56.757418
#>  ---                                                                     
#> 246: 0.9859138  4.143114 1.03655278                29.90681     30.999985
#> 247: 0.3909507  0.269518 0.06742987                34.95251      2.356843
#> 248: 0.3909507  0.269518 0.06742987                37.82832      2.550759
#> 249: 0.9762838  4.960046 1.24093869                30.88611     38.327763
#> 250: 0.4471937  0.701030 0.17538854                48.29395      8.470205


# Fit pnbd standard model WITHOUT holdout
pnc <- pnbd(clvdata(apparelTrans, time.unit="w", date.format="ymd"))
#> Starting estimation...
#> Estimation finished!

# This fails, because without holdout, a prediction.end is required
if (FALSE) {
predict(pnc)
}

# But it works if providing a prediction.end
predict(pnc, prediction.end = 10) # ends on 2016-12-17
#> Predicting from 2006-07-17 until (incl.) 2006-09-24 (10 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#>        Id period.first period.last period.length     PAlive        CET
#>   1:    1   2006-07-17  2006-09-24            10 0.19163346 0.01673295
#>   2:   10   2006-07-17  2006-09-24            10 0.07060649 0.02243407
#>   3:  100   2006-07-17  2006-09-24            10 0.99543392 4.78888517
#>   4: 1000   2006-07-17  2006-09-24            10 0.99921327 4.57683199
#>   5: 1001   2006-07-17  2006-09-24            10 0.92654506 2.10906899
#>  ---                                                                  
#> 246: 1219   2006-07-17  2006-09-24            10 0.80938690 1.74913714
#> 247:  122   2006-07-17  2006-09-24            10 0.19163346 0.01673295
#> 248: 1220   2006-07-17  2006-09-24            10 0.19163346 0.01673295
#> 249: 1221   2006-07-17  2006-09-24            10 0.88302134 1.50134084
#> 250: 1222   2006-07-17  2006-09-24            10 0.12412318 0.02513813
#>            DERT predicted.mean.spending predicted.CLV
#>   1: 0.01636655                38.64708     0.6325194
#>   2: 0.02194282                50.23072     1.1022038
#>   3: 4.68402219                37.91699   177.6040340
#>   4: 4.47661237                43.53497   194.8891855
#>   5: 2.06288637                39.80794    82.1192635
#>  ---                                                 
#> 246: 1.71083601                31.80966    54.4211122
#> 247: 0.01636655                38.64708     0.6325194
#> 248: 0.01636655                38.64708     0.6325194
#> 249: 1.46846574                34.22209    50.2539634
#> 250: 0.02458767                44.10134     1.0843494
# }