View source: R/f_interface_predict_clvfittedspending.R
predict.clv.fitted.spending | R Documentation |
Infer customer's mean spending per transaction and compare it to the actual mean spending in the holdout period.
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.
## 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,
...
)
object |
A fitted spending model for which prediction is desired. |
newdata |
A |
uncertainty |
Method to produce confidence intervals of the predictions (parameter uncertainty). Either "none" (default) or "boots". |
level |
Required confidence level, if |
num.boots |
Number of bootstrap repetitions, if |
verbose |
Show details about the running of the function. |
... |
Ignored |
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.
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.
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.
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
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())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.