predict.clv.fitted.spending: Infer customers' spending

View source: R/f_interface_predict_clvfittedspending.R

predict.clv.fitted.spendingR Documentation

Infer customers' spending

Description

Infer customer's mean spending per transaction and compare it to the actual mean spending in the holdout period.

New customer prediction

The fitted model can also be used to estimate the spending that a single, (fictional), average newly alive customer is expected to make at the moment of the first transaction. This is, for a customer which has no existing order history and that just "came alive".

The data on which the model was fit and which is stored in it is NOT used for this prediction. See examples and newcustomer.spending for more details.

Usage

## S3 method for class 'clv.fitted.spending'
predict(
  object,
  newdata = NULL,
  uncertainty = c("none", "boots"),
  level = 0.9,
  num.boots = 100,
  verbose = TRUE,
  ...
)

## S4 method for signature 'clv.fitted.spending'
predict(
  object,
  newdata = NULL,
  uncertainty = c("none", "boots"),
  level = 0.9,
  num.boots = 100,
  verbose = TRUE,
  ...
)

Arguments

object

A fitted spending model for which prediction is desired.

newdata

A clv.data object or data for the new customer prediction (see newcustomer.spending). If none or NULL is given, predictions are made for the data on which the model was fit.

uncertainty

Method to produce confidence intervals of the predictions (parameter uncertainty). Either "none" (default) or "boots".

level

Required confidence level, if uncertainty="boots".

num.boots

Number of bootstrap repetitions, if uncertainty="boots". A low number may not produce intervals for all customers if they are not sampled.

verbose

Show details about the running of the function.

...

Ignored

Details

If newdata is provided, the individual customer statistics underlying the model are calculated the same way as when the model was fit initially. Hence, if remove.first.transaction was TRUE, this will be applied to newdata as well.

To predict for new customers, the output of newcustomer.spending has to be given to newdata. See examples.

Value

An object of class data.table with columns:

Id

The respective customer identifier

actual.mean.spending

Actual mean spending per transaction in the holdout period. Only if there is a holdout period otherwise it is not reported.

predicted.mean.spending

The mean spending per transaction as predicted by the fitted spending model.

If predicting for new customers (using newcustomer.spending()), a numeric scalar indicating the expected spending is returned instead.

Uncertainty Estimates

Bootstrapping is used to provide confidence intervals of all predicted metrics. These provide an estimate of parameter uncertainty. To create bootstrapped data, customer ids are sampled with replacement until reaching original length and all transactions of the sampled customers are used to create a new clv.data object. A new model is fit on the bootstrapped data with the exact same specification as used when fitting object (incl. start parameters and 'optimx.args') and it is then used to predict on this data.

It is highly recommended to fit the original model (object) with a robust optimization method, such as Nelder-Mead (optimx.args=list(method='Nelder-Mead')). This ensures that the model can also be fit on the bootstrapped data.

All prediction parameters, incl prediction.end and continuous.discount.factor, are forwarded to the prediction on the bootstrapped data. Per customer, the boundaries of the confidence intervals of each predicted metric are the sample quantiles (quantile(x, probs=c((1-level)/2, 1-(1-level)/2)).

See clv.bootstrapped.apply to create a custom bootstrapping procedure.

See Also

models to predict spending: gg.

models to predict transactions: pnbd, bgnbd, ggomnbd.

predict for transaction models

newdata.spending to create data to predict for customers without order history

Examples


data("apparelTrans")

# Fit gg model on data
apparel.holdout <- clvdata(apparelTrans, time.unit="w",
                           estimation.split = 52, date.format = "ymd")
apparel.gg <- gg(apparel.holdout)

# Estimate customers' mean spending per transaction
predict(apparel.gg)

# Estimate the mean spending per transaction a single,
# fictional, average new customer is expected to make
# See ?newcustomer.spending() for more examples
predict(apparel.gg, newdata=newcustomer.spending())




CLVTools documentation built on April 4, 2025, 2:02 a.m.